In Scheme, are primitive procedures considered special forms?
Also, a bit too general but how is define
different from other special forms?
In Scheme, are primitive procedures considered special forms?
Also, a bit too general but how is define
different from other special forms?
Being primitive has nothing to do with being a special form. The main difference between special forms and procedures are that procedures have all their arguments evaluated before it's applied. That's the same difference as between user defined special forms and user defines procedures.
In the Scheme report a primitive is the syntax and procedures you need to implement in the underlying system. Eg. if you make Scheme in Java you'll need to make the primitive syntax and procedures in Java. The rest you can define in terms of the primitives in Scheme itself. E.g. if
is primitive syntax while cond
is called library syntax. cond
you just make a syntax-rule for and voilĂ ; it uses the if
primitive. Primitive procedures are the same. I.e. They are the procedures you need to define the rest of the Scheme report. What's primitives and whats not isn't essential for programming in Scheme, only for the ones who wants to use the report to implement Scheme needs these hints.
define
is a very special primitive syntax. It truly is a primitive for top level binding since it's the only way to define a new top level bindings, but when you see it within procedure definitions it's really not much of a primitive. It can be written as a letrec*
which in terms can be implemented with anonymous procedure calls and set!
. I guess it's nice to have the same name for the special form to make both global and local bindings so it's a practical reason, but if Scheme would change to have different names only the one adding global bindings would be a primitive.
are primitive procedures considered special forms?
No. There's nothing special about primitive procedures - they act exactly like user defined procedures. See R5RS - standard procedures for more info.
how is
define
different from other special forms?
Well, one thing which comes to my mind is that most special forms (if
,let
) return normal scheme values and can appear everywhere, while a define
block return value is not defined by the standard and can only be executed in top-level or in the body of another special form. See R5Rs - define.