Search found 28 matches

by stackman
Wed Oct 24, 2012 7:17 am
Forum: Common Lisp
Topic: Binary search tree obscure code...
Replies: 5
Views: 16588

Re: Binary search tree obscure code...

Everything is fine in the code, you're just confused by what the call to a struct returns. When you eval nums at the repl, the :print-function defined by defstruct is called and returns a string of the form #<5>, where 5 is the element stored in the main node of your tree. Graham returns a string of...
by stackman
Sat Oct 20, 2012 1:54 pm
Forum: Common Lisp
Topic: strange error with mapcan and quote.
Replies: 1
Views: 3088

strange error with mapcan and quote.

I get a weird behavior with sbcl when I try the following code at the repl. (mapcan (lambda (x) (if (evenp x) '(even))) (list 1 2 3 4)) Sbcl hangs at 100% CPU without returning an error. Why do I get such a behavior? Apparently, this is related to the quote '(even). If I replace it by (list 'even), ...
by stackman
Fri Oct 19, 2012 1:38 am
Forum: Common Lisp
Topic: loop keywords
Replies: 4
Views: 7407

Re: loop keywords

Ah, I understand now. Thanks for the thorough answer.
by stackman
Thu Oct 18, 2012 1:20 am
Forum: Common Lisp
Topic: loop keywords
Replies: 4
Views: 7407

loop keywords

Hi, I see sometimes loop forms written as follows. (loop :for x :from 1 :to 10 :collect x) Why do some people prefix the loop keywords with a colon? Is this required by some implementations? The hyperspec insists on the fact that "Loop keywords are not true keywords." So why does the use of true key...
by stackman
Thu Oct 18, 2012 1:01 am
Forum: Common Lisp
Topic: fractional part of a number
Replies: 3
Views: 5052

Re: fractional part of a number

Thanks for the replies, this is definitely better.
by stackman
Mon Oct 15, 2012 1:35 pm
Forum: Common Lisp
Topic: fractional part of a number
Replies: 3
Views: 5052

fractional part of a number

Hi,
Is there a simple way to return the fractional part of a number in common lisp?
At the moment I am using

Code: Select all

(multiple-value-call (lambda (x y)(declare (ignore x)) y) (floor 1.5))
but this seems a bit verbose.
by stackman
Mon Oct 15, 2012 8:50 am
Forum: Common Lisp
Topic: true function
Replies: 3
Views: 4871

Re: true function

This does not give exactly the same result.

Code: Select all

CL-USER> (some 'identity (list nil "no" nil))
=> "no"
CL-USER> (notevery 'not (list nil "no" nil))
=> T
So I guess there is no builtin true function.
Anyway, thanks for the answer.
by stackman
Sat Oct 06, 2012 6:23 am
Forum: Common Lisp
Topic: true function
Replies: 3
Views: 4871

true function

Hi, is there a "true" function in Common Lisp ? I mean does there exist a function that returns t for all non nil values of its argument, and nil if its argument is nil? There are at least two "false" functions, not and null, which are strictly equivalent, but I was not able to locate a "true" funct...