5 promitive procedures are applied as follows:
7 (define (apply-primitive-procedure proc args)
8 (apply-in-underlying-scheme
9 (primitive-implementation proc) args))
11 Let us say that we have added `map' as a primitive procedure. It is represented as
14 (primitive-implementation)
16 > (define primitive-procedures
23 > (define (primitive-procedure-names)
25 primitive-procedures))
26 > (primitive-procedure-names)
27 '(car cdr cons null? map)
28 > (define (primitive-procedure-objects)
29 (map (lambda (proc) (list 'primitive (cadr proc)))
30 primitive-procedures))
31 > (primitive-procedure-objects)
32 '((primitive #<procedure:car>) (primitive #<procedure:cdr>) (primitive #<procedure:cons>) (primitive #<procedure:null?>) (primitive #<procedure:map>))
34 > (apply (primitive-implementation (list 'map map)) (primitive-implementation (list 'car car)) '(((1 2 3) (3 4 5))))
36 > (apply (primitive-implementation (list 'primitive map)) (primitive-implementation (list 'primitive car)) '(((1 2 3) (3 4 5))))
38 > (apply (primitive-implementation (list 'primitive map)) (list 'primitive car) '(((1 2 3) (3 4 5))))
39 map: expects type <procedure> as 1st argument, given: '(primitive #<procedure:car>); other arguments were: '((1 2 3) (3 4 5))
42 If we apply primitive procedures to our primitive map, it fails because it cannot understand our primitive representation.
43 In general, all primitive versions of higher order functions fail when passes a primitive procedure.
45 If we are implementing Scheme using a Lisp other than Scheme itself (say, Clojure) then we will be passing Scheme functions
46 to the Clojure's map, which is not guaranteed to work because of the different syntax.