Re: Lisp Syntax - functions versus data



In article <1172557054.945971.84460@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
"S. Robert James" <srobertjames@xxxxxxxxx> wrote:

I'm still struggling to master some of the finer points of Lisp
syntax. Not the S-expressions, mind you, but the rules for forms
being either evaluated, referring to data, or referring to
functions...

I'm trying:
(defun mapcar. (func lst)
(if (null lst)
()
(append (list (funcall func (car lst))) (mapcar. func (cdr
lst)))))

(= '(3 4 5 6) (mapcar. '(lambda (x) (+ 3 x)) '(0 1 2 3)))

but can't get it to work... how should this be quoted? Should I
switch to Scheme, which seems to have simpler syntax?

What kind of error do you get?

I see:

(LAMBDA (X)
(+ 3 X)) is not of type (OR SYMBOL FUNCTION), and can't be FUNCALLed
or APPLYed

A function needs ro be quoted by #' .

So:

(= '(3 4 5 6) (mapcar. #'(lambda (x) (+ 3 x)) '(0 1 2 3)))

Then you get:

value (3 4 5 6) is not of the expected type NUMBER.

Because = is only for comparing numbers.

See:
http://www.lisp.org/HyperSpec/Body/fun_eqcm_sleq__lteqcm_gteq.html

So:

(equal '(3 4 5 6) (mapcar. #'(lambda (x) (+ 3 x)) '(0 1 2 3)))


Also:

Try to write MAPCAR. without APPEND. Using APPEND is often inefficient.
.



Relevant Pages

  • Re: Lisp Syntax - functions versus data
    ... being either evaluated, referring to data, or referring to ... which seems to have simpler syntax? ... I just pasted your code into my lisp and it worked. ...
    (comp.lang.lisp)
  • Re: Lisp Syntax - functions versus data
    ... being either evaluated, referring to data, or referring to ... which seems to have simpler syntax? ... "(defun mapcar. ...
    (comp.lang.lisp)
  • Lisp Syntax - functions versus data
    ... Not the S-expressions, mind you, but the rules for forms ... being either evaluated, referring to data, or referring to ... which seems to have simpler syntax? ...
    (comp.lang.lisp)
  • Re: Forms! syntax question
    ... >Where "TMS Switchboard" is the name of the form. ... >syntax if the name of the form is contained in a string variable? ... You can use *three* different syntaxes for referring to ... the sequential number in parentheses (not ...
    (microsoft.public.access.formscoding)
  • Re: Forms! syntax question
    ... > Subform control, but - though it's evidently legal here - it's not ... >>syntax if the name of the form is contained in a string variable? ... You can use *three* different syntaxes for referring to ... > the members of a collection: the sequential number in parentheses (not ...
    (microsoft.public.access.formscoding)