Search found 106 matches

by Paul
Mon Nov 12, 2012 2:50 pm
Forum: Homework
Topic: Finding Depth of an Expression
Replies: 3
Views: 10258

Re: Finding Depth of an Expression

Hi, I'm incredibly new to Lisp and I've got to write a program that calculates the depth of an expression. Here's what I've got so far: (DEFUN depth (L) (IF (NIL L) 0) (IF (NIL (SECOND L)) 0) (IF (ATOM (SECOND L)) (1+depth(CDR L))) ) What it's supposed to do is return 0 if the list L is empty or on...
by Paul
Mon Nov 12, 2012 1:28 am
Forum: Common Lisp
Topic: Problem with "initialize-instance"
Replies: 5
Views: 8658

Re: Problem with "initialize-instance"

Thank you for the explanation! I would say this is not so economic behaviour of LISP processor, to run first all available methods and then to choose appropriate result. It seems much more natural to choose first appropriate method and then to run it. It doesn't run them and then choose a result; i...
by Paul
Sun Nov 11, 2012 5:58 pm
Forum: Common Lisp
Topic: Replacing a function in an expression
Replies: 20
Views: 37565

Re: Replacing a function in an expression

Check the version with macroexpand-dammit out, but it also expands into the implementation-dependent code because of compiler macros (for example append with two args into sb-impl::append2 under SBCL). But that shouldn't matter, because SB-IMPL::APPEND2 must be a function (assuming it's been fully ...
by Paul
Sun Nov 11, 2012 5:45 pm
Forum: Common Lisp
Topic: Replacing a function in an expression
Replies: 20
Views: 37565

Re: Replacing a function in an expression

@ Paul Are there implementation independant common lisp code walkers? A quick google search suggests that there are a few edge cases which are not so easy to handle. The trouble is, the environment access stuff didn't make it into the standard, so if you want to write a portable code-walker, you ha...
by Paul
Sun Nov 11, 2012 5:38 pm
Forum: Common Lisp
Topic: Problem with "initialize-instance"
Replies: 5
Views: 8658

Re: Problem with "initialize-instance"

Situation is not so easy. The code (defmethod initialize-instance :after ( (item Big) &key ) (setf (my-value item) 666 ) ) (setf x (make-instance 'Small ) ) results in creating an instance "x" having my-value 13, as expected since the method of initialization for the class "Small...
by Paul
Sun Nov 11, 2012 2:28 pm
Forum: Common Lisp
Topic: Problem with "initialize-instance"
Replies: 5
Views: 8658

Re: Problem with "initialize-instance"

But by some reason attempts to create instances of the class "Small", e.g. calls (setf x (make-instance 'Small ) ) also give the same error message saying that (Func 666) cannot be computed! My question is: why "initialize-instance" chooses method for the class "Big" e...
by Paul
Sun Nov 11, 2012 2:26 pm
Forum: Common Lisp
Topic: Replacing a function in an expression
Replies: 20
Views: 37565

Re: Replacing a function in an expression

Unfortunately there is no implementation independent way to do this since every implementations has it's own special forms. But usually the number of special forms is small wich makes it feasible to write different versions for different implementations. No. The special forms/operators are defined ...
by Paul
Sat Nov 10, 2012 8:21 pm
Forum: Homework
Topic: Array element type: CLISP / SBCL
Replies: 1
Views: 6751

Re: Array element type: CLISP / SBCL

What you really mean is that it doesn't work in CLISP -- you've asked that the array only be able to hold double-floats, and then tried to put a symbol into it. Since a symbol is not a double-float, this should be an error. But no Lisp can have specialized arrays for every possible type, so you can ...
by Paul
Sun Nov 04, 2012 3:21 pm
Forum: Common Lisp
Topic: end chapter exercise's doubts...
Replies: 7
Views: 12759

Re: end chapter exercise's doubts...

No. Yours pointlessly calls POSITION to find something you've already located, but otherwise they're the same (except for REMOVE-DUPLICATES). (PUSH x y) == (SETQ y (CONS x y))
by Paul
Fri Nov 02, 2012 10:43 pm
Forum: Common Lisp
Topic: A reader macro in a macro
Replies: 9
Views: 15123

Re: A reader macro in a macro

The problem is, the OP wanted to write (#_new ,@(rest var)) and #_ apparently wants to read two more symbols from the input stream to find out what to expand into (i.e., NEW and QLABEL) — so ,@(rest var) needs to be expanded before the reader macro takes hold. Which tells you you're doing somethin...