lisp related (33)

1 Name: #!/usr/bin/anonymous : 2007-07-11 21:05 ID:ierxpXZU

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..

2 Name: dmpk2k!hinhT6kz2E : 2007-07-12 00:13 ID:Heaven

I think you have the braces a bit mixed up. Try this:

(let (a (list 4 8 2 7 9)) 
(sort a #'>))

3 Name: #!/usr/bin/anonymous : 2007-07-12 03:04 ID:Heaven

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.

4 Name: dmpk2k!hinhT6kz2E : 2007-07-12 03:13 ID:Heaven

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 #'>))

5 Name: #!/usr/bin/anonymous : 2007-07-13 06:50 ID:Heaven

ah, thanks >>2,4 that works great
actually you had a small typo on >>4 but i noticed it :P

6 Name: dmpk2k!hinhT6kz2E : 2007-07-14 04:29 ID:iceXcLVO

>>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 Name: #!/usr/bin/anonymous : 2007-07-15 03:28 ID:Heaven

>>6
being able to understand exactly what the code does almost as fast as i can read it is nice. and "))))" makes my eyes bleed.
FFT in factor
FFT in scheme
FFT in common lisp
FFT in haskell

8 Name: dmpk2k!hinhT6kz2E : 2007-07-16 03:24 ID:Heaven

>>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.

9 Name: #!/usr/bin/anonymous : 2007-07-16 14:25 ID:Heaven

>>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 Name: #!/usr/bin/anonymous : 2007-07-18 01:37 ID:aw6epUTq

>>3

(sort '(4 8 2 7 9) #'>)

......
amazing, isn't it?

11 Name: not 20 : 2007-07-18 11:15 ID:Heaven

>>10
that looks like one of those elaborate 2ch emoticons gone horribly wrong

12 Post deleted by moderator.

13 Name: #!/usr/bin/anonymous : 2007-07-19 17:05 ID:Heaven

>>10
how would you do this in lisp?

[ dup 2 rem - - ] sort

14 Name: #!/usr/bin/anonymous : 2007-07-19 18:37 ID:WYEBRR0+

perl -e "print join q{ },sort 4,8,2,7,9"

15 Name: #!/usr/bin/anonymous : 2007-07-19 18:38 ID:WYEBRR0+

Wait a second, i though i was on 4chan's dis
How did i even get here?

16 Post deleted by moderator.

17 Post deleted by moderator.

18 Name: #!/usr/bin/anonymous : 2007-07-20 03:40 ID:Heaven

19 Post deleted by moderator.

20 Name: #!/usr/bin/anonymous : 2007-07-23 12:20 ID:Heaven

What's with all the deleted posts?

21 Name: #!/usr/bin/anonymous : 2007-07-24 14:18 ID:V6lot3V3

FURSECUTION

22 Name: #!/usr/bin/anonymous : 2007-07-24 21:41 ID:0cxcHD1d

I am heavily vershed in lishp.

23 Name: #!/usr/bin/anonymous : 2007-08-13 08:50 ID:2dKef5It

>>10
sort is destructive, and self-modifying code is a bad idea.
[code](sort (list 4 8 2 7 9) #'>)[/code]

24 Name: #!/usr/bin/anonymous : 2007-08-17 03:02 ID:7QL+dMzb

>>23 C's qsort() is just as "destructive".

25 Name: #!/usr/bin/anonymous : 2007-08-21 06:06 ID:4jC68jdw

>>24

*l = calloc(n, sizeof *l);
if(l != NULL) {
memcpy(l, somelist, n);
qsort(l ..);
}
ret l;

26 Name: #!/usr/bin/anonymous : 2007-08-21 06:19 ID:uewzS13A

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.

27 Name: #!/usr/bin/anonymous : 2007-08-21 11:46 ID:Heaven

Whoops, it seems a carefully implemented quicksort can run in log(n) space in the worst case after all.

28 Name: #!/usr/bin/anonymous : 2007-08-26 23:26 ID:Bg6JzXAj

>>13
maybe. I don't know what it does.
>>23
true, I didn't remember sort was destructive.

29 Name: #!/usr/bin/anonymous : 2007-08-27 19:25 ID:Heaven

>>28

( 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 }

30 Name: #!/usr/bin/anonymous : 2007-09-02 01:13 ID:j2xaQ+yh

CAT SCRATCH FEVER!!!

31 Name: #!/usr/bin/anonymous : 2007-12-14 01:36 ID:7QL+dMzb

>>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.

32 Name: #!/usr/bin/anonymous : 2007-12-14 08:32 ID:Nvzh4m9t

>>1
Hey, I found your problem: you're trying to write code in the REPL.

33 Name: #!/usr/bin/anonymous : 2007-12-14 18:27 ID:7QL+dMzb

>>32
The REPL is a perfectly good place to write code.

This thread has been closed. You cannot post in this thread any longer.