Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

lisp newbie help

Name: Anonymous 2012-01-01 5:46

if i set the value of a symbol to a function, how do i call it with that symbol?

(setq a #'append)
(a ... ) <--how do i do this?

thanks

Name: Anonymous 2012-01-01 5:51

>>1
(a ...)

Name: Anonymous 2012-01-01 5:55

>>2
error :function A is not defined

Name: Anonymous 2012-01-01 6:03

>>2

ja that only works in the scheme like ones, where functions and variables reside in the same namespace.

Ya gata do it like:

(funcall a ...)

You call a function that takes a variable (which is a function)

You could also do (apply a (...)), which can be more convenient at times.

Some people hate this. Some like variables being in a different name space than functions so you can do:

(defun list (list)
 (if (null? list)
   1
   (list (cdr list))))

I personally perfer being able to call variables that happen to be functions using the same syntax for calling functions.

Name: VIPPER 2012-01-01 6:09

>>1
Tell us what language you are using.
Some have a separate namespace for functions, while others dont.

Name: Anonymous 2012-01-01 6:09

>>4
thanks bro

Name: Anonymous 2012-01-01 6:12

(defun list (list)
 (if (null? list)
   1
   (list (cdr list))))


Who the fuck would do that? That's not a reason for functions and variables to be divided.

Here's how to solve your problem:

[1]> (exit)
Bye.
$ guile
guile> (define a append)
guile> (define x '(1 2 3))
guile> (a x x)
(1 2 3 1 2 3)

Name: >>4 2012-01-01 6:30

>>7
indeed

Name: Anonymous 2012-01-01 6:31

>>7
Whoa, for some reason I always thought Guile was a CL implementation, not Scheme.

Name: Anonymous 2012-01-01 11:32

(lisp (is (for (faggots))))

Name: Anonymous 2012-01-01 18:41

What was the real reason for an arbitrary number of namespaces in those lisps anyway? It looks to be related to pre-von Neumann concerns. The idea of having the privilege of a list variable inside a list function looks stupid. You end up with N setters and N ways to get things... Even C doesn't do this (though C does have separate namespaces for things like structs, but those don't form valid operations much with functions and variables except through things like sizeof).

Name: Anonymous 2012-01-01 18:43

>>11
It's just a historical thing.

Name: Anonymous 2012-01-01 19:43

>>11
Makes writing macros easier, also you don't have to rename your variables to not match with functions (I tend to use variables named like string, list all the time).

The full reason is explained here:
http://www.nhplace.com/kent/Papers/Technical-Issues.html

Name: Anonymous 2012-01-01 22:09

>>11
Hygienic macros didn't exist back then, using multiple namespaces helped avoiding captures.

Name: Anonymous 2012-01-02 0:29

>>12-14
aah ありがとう

Don't change these.
Name: Email:
Entire Thread Thread List