freenode/#lisp - IRC Chatlog
Search
10:51:02
Josh_2
basically I would like to have a slot within a class with a set name like 'symbol-slots' then when I (make-instance 'special-class :symbol-slots '(a b c d e)) then I will get an instance with the slots symbol-slots a b c d and e.
10:51:52
Josh_2
so the initarg :symbol-slots would be converted to effective slots and appended to my instance
10:57:14
phoe
this sounds like a method on INITIALIZE-INSTANCE that accepts :SYMBOL-SLOTS and goes CALL-NEXT-METHOD with an appropriately frobbed :DIRECT-SLOTS argument
10:57:55
phoe
like, (defmethod initialize-instance ((class special-class) &rest args &key direct-slots &a-o-k) (call-next-method ...))
10:58:32
phoe
where in ... you remove SYMBOL-SLOTS from the ARGS plist and also pass a modified DIRECT-SLOTS argument
11:01:56
phoe
all you want to do is to modify the way in which the instance is initialized, by means of stuffing more direct slot definitions in there
11:43:56
Josh_2
okay so I have made my new effective slots that I want to append, I just don't know how to append them in make-instance
12:18:54
Josh_2
"The generic function update-instance-for-redefined-class is not intended to be called by programmers."
12:21:45
_death
when you evaluate a defclass it may get called, to update instances for redefined class
12:30:27
jmercouris
it is possible, I'm just suggesting that you may wish to go another route if you will find yourself doing things like this
12:32:24
Josh_2
I was basically just messing around and seeing if I *could* do it because I thought it would be a nice way for users to interact with request objects
12:33:06
Josh_2
instead of having to look through a list they could just set/get from a slot, a slot that is dynamically added depending on some data that is passed
12:35:01
Josh_2
well the slots would have to be appended based on the value of an initarg when calling make-instance
12:42:38
jmercouris
"Stealth Mountain (@StealthMountain) is a Twitter bot with a single, simple purpose: It searches for tweets in which a person has typed the words “sneak peak” when they meant to type “sneak peek,” then publishes a reply informing the author of his error. "
12:43:31
_death
if the objective is to learn about the MOP, then I remember AMOP had an example concerning dynamic slot storage
12:45:46
Josh_2
but they have all their slots predefined but wish to only allocate slots when needed
12:47:16
_death
I see.. well, the last time I did something with the MOP was years ago, so someone else may be of help ;)
13:18:13
jackdaniel
you 1) did not paste the macro itself; 2) you did not state the problem correctly
13:20:03
jackdaniel
and it is quite surprising given that a considerable wall of text has been written ,)
13:21:27
phoe
stirring this further will bring no good to either of you or to #lisp, and right now it's both of you stirring this up
13:22:33
jackdaniel
phoe: hm, I consider myself perfectly calm, what i'm saying is that he should state a question which could be reasoned about (i.e correctly state the problem), not really sure how is this stirring things
13:24:48
jmercouris
I've rewritten and destroyed the macro several times, still not able to achieve what I am trying to...
13:25:59
jmercouris
and in execute-extended-command it would be applying like this: (qrt optional-arguments)
13:27:08
phoe
if these come from the DEFINE-COMMAND lambda list, you might want to use ALEXANDRIA:PARSE-ORDINARY-LAMBDA-LIST to get the required/optional/keyword/whatever arguments and such
13:33:20
phoe
these do not depend on each other so we can generate those separately via mapcar, just like jackdaniel mentioned earlier
13:33:38
jmercouris
OK and then finally you have the actual function %qrt which basically wraps everything in with-result
13:33:39
phoe
my code is just somewhat more verbose to avoid double backquote and make explicit separation of concerns
13:34:05
phoe
yes, the actual body of %qrt generates the full form and splices in the results of subfunctions
13:34:52
phoe
(mostly in hope that this technique is somewhat easy to grok and understand and then repeat and reuse)
13:35:36
phoe
I mean, you could probably read the PCS source if you want more examples of this macro style
13:36:08
phoe
except there I use global functions instead of local ones for even more verbosity and ease of REPL-based testing and twiddling
13:37:13
phoe
you can get rid of the intermediate function and stuff its body inside the macro, and things will work.
13:38:10
phoe
and inside https://github.com/phoe/portable-condition-system/tree/master/src the files of interest are assertions.lisp, handlers.lisp, restarts.lisp
13:38:54
phoe
even though that one is really boring except for report methods, because it expands into DEFCLASS :D
13:51:30
phoe
anyway, I think this is how such situations should be handled - in case of not enough information or a poorly specified problem, 1) please ask for more details instead of stating the obvious, 2) please provide more details even if the obvious was stated
13:53:03
phoe
truth be told, this might have ended with a firestorm, some banhammering, and overall bad smell on #lisp if I weren't here to calm things down a bit
14:28:42
gendl
emacs 27.1 warns that package cl is deprecated if we are requiring it at load time. If we can load .elc files, apparently this warning will not happen.
14:29:10
gendl
jmercouris: this isn't the right channel for slime questions? Is there a #slime channel?
14:29:21
mfiano
File a bug ticket with whoever wrote code using the very old cl library. They should be using cl-lib now.
14:30:31
gendl
just found the #slime channel, thanks. btw it looks like slime depends on 'cl just for two symbols.
15:12:16
mfiano
I see. I didn't have enough interest in the real inferior-lisp to go refresh my memory.
17:15:04
Josh_2
I am already storing an association between strings and symbols, I can just create slots from the symbols and use those within compute-slots
18:17:36
Josh_2
I added :readers to :initargs but my instance that uses these new slots doesn't have any associated readers
18:38:00
Bike
not sure i understand. you have a keyword argument called "initargs"? what's special-slot look like?
18:38:39
Bike
also, the direct slots need to actually be in the direct slots of the class. they're not, here
18:39:05
Bike
you can't just add effective slots that don't correspond to any direct slots, as far as i know
18:39:18
Bike
effective slots don't have readers or writers, so the information would be discarded, anyway
18:40:12
Bike
if you want instances of your metaclass to have extra slots the easiest thing to do is just to define a superclass for all the instances, and put those slots in the superclass
18:40:49
Bike
i don't know if that's allowed, and if it is, the rest of the system is going to ignore it unless you put in special processing
18:43:04
Bike
slot definitions are properties of classes. classes have slot definitions. instances do not have slot definitions, they have slots.
18:43:25
Bike
In this scenario, do you have different instances of the same class that have different accessible slots?
18:43:50
Bike
compute-slots is called when you define a class. it's not called for every instance, or anything like that.
18:44:29
Bike
You need to decide what exactly you want. A class that can have slots added and removed is a lot different from flexible instances.
18:48:33
Josh_2
so basically redefine a class with a new slot each time I find a new header, and then create an instance of that
18:52:52
Josh_2
I basically did. In the plaster code there is a list called *slots-needed* now imagine that every once in a while a new symbol is added automatically and the class 'request' would need to update itself with the new slot
18:53:28
Bike
Why would you want instances of the same class to have different slots? That's confusing.
18:54:54
Bike
okay. so just do (eval `(defclass classname (supers...) ,@*slots-needed*)) when you change *slots-needed*.
18:55:12
Bike
and if that's what you want you can do that a little better with ensure-class instead, but it's still like a line of code.
18:57:22
Bike
I really don't understand your architecture here. How many instances of this class are relevant at any given time?
20:09:58
_death
I guess what Josh_2 is trying to do is usually a basic feature of frame based systems..
20:12:57
_death
for example, Parmenides (which can be made to run on today's CL implementations with a few easy tweaks) has add-slot <classname> <slot-name> <slot-contents> &key cache
20:28:12
_death
there was a good survey of frame representation systems.. http://www.ai.sri.com/pub_list/236
20:29:35
Lycurgus
i knew of it (parmenides) but now it occurs in the context of relief from encumbered frame systems
20:30:40
_death
what do you mean? (I played with it some years ago, but otherwise don't have much experience with those)
21:58:03
jcowan
What's the general view in the CL community about error conditions? Is it usual to just use condition type ERROR or to create your own subtype?
22:00:31
Xach
jcowan: it is pretty common to create your own conditions of the approprite type, which is often (but not always) a subtype of error.
22:01:26
Xach
and the custom condition helps distinguish your condition from others that aren't of interest
22:03:28
Xach
I usually think of (error "foo ~A" bar) as the quick and dirty first version and refine as time allows and need dictates
22:05:42
jcowan
The debate I'm having with a colleague is this. Given a document that is MIME-labeled with an unknown encoding name, what to do? We agree that returning NIL is a bad idea; I think the situation is rare enough that returning a generic condition type is enough, whereas my cow orker is strongly in favor of a unique type. Disregard for the moment the question of relevant information; the datum argument is enough.
22:07:30
Xach
I would make a unique type, and if the data isn't important, it would be as simple as (define-condition unknown-encoding-error (error) ())
22:08:06
Xach
There are so many other errors that might happen and being able to distinguish is very helpful later, as phoe suggests.
22:08:11
phoe
which means that the programmer cannot customize program behavior in case an unknown MIME label is encountered
22:11:43
jcowan
Well. The answer to that would have been to use predicates rather than types in handler-bind. But nooooo.
22:12:57
phoe
still, using a a SATISFIES type plus a named function that searches for substrings in condition reports is more ugly than using a proper condition type.
22:14:30
jcowan
My colleague is often very very very annoying. He makes up for this by sometimes (often?) being very very right.
22:15:00
fwoaroof[m]
Xach: that's my preference, for simple conditions: do the ugly string thing, but do it in a wrapper that signals a unique condition type
22:15:53
fwoaroof[m]
Also (and base-condition-1 base-condition-2) for the common subclasses of two conditions might occasionally be useful
22:15:54
jcowan
I mean, write a macro that can do OR-types and AND-types for you and use it instead of handler-bind
22:16:37
fwoaroof[m]
Sure, you can do predicates or whatever, but I actually like the type system in CL :)
22:16:41
jcowan
It's certainly a reasonable choice, but if you have predicates you can easily get types; vice versa, not so much.