i'm trying to do something really basic in Lisp
i want to sort a list, yep that's about it.
that's what i'm trying:
[code]((let a (list 4 8 2 7 9)) (sort a #'>))[/code]
and i get this error
[code]
*** - EVAL: (LET A (LIST 4 8 2 7 9)) is not a function name; try using a
symbol instead
The following restarts are available:
USE-VALUE :R1 You may input a value to be used instead.
ABORT :R2 ABORT
[/code]
help..
I think you have the braces a bit mixed up. Try this:
(let (a (list 4 8 2 7 9))
(sort a #'>))
lol lisp.
{ 4 8 2 7 9 } [ drop ] sort
or { 4 8 2 7 9 } natural-sort reverse
ftw.
that's factor, btw. much clearer than that crazy lisp syntax.
I think I got >>2 wrong. I don't have a CL or Scheme install here. This is (probably) better:
(let ((x '(4 8 2 7 9)))
(sort a #'>))
>>3
I've noticed someone arguing on 4chan's boards for Factor. Maybe you'd be willing to elaborate a bit on why you like it?
>>7
Interesting. I delight in terse code built on simple constructs.
I've downloaded Factor and started playing a bit with it. Are there any tutorials you would recommend? The version on factorcode and in the listener is a bit bare.
>>8
sorry, i don't usually read tutorials...
i've learned most of what i know from reading http://factorcode.org/responder/help/ and http://factorcode.org/responder/browser/ and the code that's included in the download.
>>10
that looks like one of those elaborate 2ch emoticons gone horribly wrong
>>10
how would you do this in lisp?
[ dup 2 rem - - ] sort
perl -e "print join q{ },sort 4,8,2,7,9"
Wait a second, i though i was on 4chan's dis
How did i even get here?
What's with all the deleted posts?
FURSECUTION
I am heavily vershed in lishp.
>>10
sort is destructive, and self-modifying code is a bad idea.
[code](sort (list 4 8 2 7 9) #'>)[/code]
>>23 C's qsort() is just as "destructive".
*l = calloc(n, sizeof *l);
if(l != NULL) {
memcpy(l, somelist, n);
qsort(l ..);
}
ret l;
Criticizing quicksort on the basis of it being destructive is frankly nonsensical. After all, isn't the main benefit of quicksort that it can run in constant heap space? (Though I've heard said that quicksort may consume n^2 stack space in the worst case; not so hot after all.)
Also, don't use quicksort in an environment where input may have been prepared by a hostile party. Or vet such inputs beforehand for the pessimal-ish cases and switch to merge- or radix sort.
Whoops, it seems a carefully implemented quicksort can run in log(n) space in the worst case after all.
( scratchpad ) { 0 1 2 3 4 5 6 7 8 9 10 11 } [ dup 2 rem - - ] sort .
{ 1 0 3 2 5 4 7 6 9 8 11 10 }
CAT SCRATCH FEVER!!!
>>13 { 0 1 2 3 4 5 6 7 8 9 10 11 } [ dup 2 rem - - ] sort
could be implemented as (nreverse (sort '(0 1 2 3 4 5 6 7 8 9 10 11) (lambda (a b) (> (- a (mod a 2)) b))))
although I'm not sure why you'd want to do that. I'm curious as to where [ dup 2 rem -- ]
came from.
On the other hand, it may simply go to show that almost everything is a valid command in factor (like forth and postscript), but only one thing is really what you wanted.