Function as a parameter

Discussion of Common Lisp

Re: Function as a parameter

Postby wvxvw » Thu Jun 28, 2012 3:49 am

What you refer to is commonly known as binding. I.e. An identifier in environment (a term in the program code) which is bound (refers to) some value.
E.g. in CL:
Code: Select all
(let ((foo 42))
  (princ foo))

In the case above let creates an environment which inherits all bindings from the surrounding environments and adds a binding for the identifier foo to the value 42.
Something very similar happens in C:
Code: Select all
  int foo = 42;
  printf("%d", foo);

where you created a binding to the identifier foo in the block of code.
If you want to print an array or a member of an array, you would do something like this:
Code: Select all
(let ((foo #(1 2 3)))
  (princ foo)
  (princ (aref foo 1)))

However, it is imprecise to say that "array has a name". Objects don't have name in general, unless you create some such property of an object. "Names" are designations of where the objects are located. Thus, for example:
Code: Select all
(let* ((foo (list 1 2 3))
      (bar (rplaca foo 0)))
(princ foo)
(princ bar))

will print: (0 2 3) (0 2 3). I.e. both foo and bar are the "names" of the same list.
Posts: 127
Joined: Sat Mar 26, 2011 6:23 am


Return to Common Lisp

Who is online

Users browsing this forum: Majestic-12 [Bot] and 4 guests