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

Pages: 1-

function vs fdefinition

Name: Anonymous 2010-04-08 3:07

Why does everyone teach (function x) over (fdefinition 'x)?
It disturbs me to no end that no one actually bothers to read the not-so-mundane sections of the CLHS. Hell, even fdefinition has a setf partner!

(inb4: "why not just use define")

Name: Anonymous 2010-04-08 3:09

If only you had a language with a single environment as proper ADTs of their own.

(yes, not even Scheme has that.)

Name: Anonymous 2010-04-08 5:17

Compare.
(flet ((foo () 'x))
  (fdefinition 'foo))
(flet ((foo () 'x))
  (function foo))


It disturbs me that you haven't bothered to read the relevant sections of the CLHS.

Name: Anonymous 2010-04-08 5:49

Read the definition of fbound.

Name: Anonymous 2010-04-08 11:59

>>1
[m][i]Accessor[i][/m] FDEFINITION[/m]
fdefinition accesses the current global function definition named by function-name.

Special Operator FUNCTION
The value of function is the functional value of name in the current lexical environment.

As you can see, the semantics are rather different.

There's also symbol-function, btw, which accesses the symbol's function cell (although, it could be implemented as a separate namespace too, that's up to the implementors to decide).

Consider:

(flet (((setf a) (v) v)) (values (setf (a) 3) #'(setf a))) ;=>
3
#<FUNCTION (FLET (SETF A)) {24BBC085}>

(flet (((setf a) (v) v)) (values (setf (a) 3) (function (setf a)))) ;=>
3
#<FUNCTION (FLET (SETF A)) {24BFA85D}>
;;; #'... is just a reader macro which expands to (cl:function ...)

(flet (((setf a) (v) v)) (values (setf (a) 3) (fdefinition '(setf a)))) ;=>
The function (SETF A) is undefined.
   [Condition of type UNDEFINED-FUNCTION]
...
;;; FDEFINITION does not work lexically, but it does work on global definitions:

(fdefinition '(setf fdefinition)) ;=> #<FUNCTION (SETF FDEFINITION)>

Name: >>5 2010-04-08 12:09

Also, SETF'ing a lexical definition wouldn't make as much sense. You can just shadow it if you want.

Name: ​​​​​​​​​​ 2010-10-22 22:36

Name: Anonymous 2011-02-04 11:49

Name: Anonymous 2011-02-18 14:18

<-- check 'em dubz

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