more primitives
This commit is contained in:
parent
c066bdf568
commit
a66d15e4e4
|
@ -181,7 +181,26 @@
|
||||||
l
|
l
|
||||||
(memq x (cdr l)))))])
|
(memq x (cdr l)))))])
|
||||||
memq))
|
memq))
|
||||||
|
(make-bootstrapped-primitive-code
|
||||||
|
'memv
|
||||||
|
'(letrec-values ([(memv) (lambda (x l)
|
||||||
|
(if (null? l)
|
||||||
|
#f
|
||||||
|
(if (eqv? x (car l))
|
||||||
|
l
|
||||||
|
(memv x (cdr l)))))])
|
||||||
|
memv))
|
||||||
|
|
||||||
|
(make-bootstrapped-primitive-code
|
||||||
|
'memf
|
||||||
|
'(letrec-values ([(memf) (lambda (x f l)
|
||||||
|
(if (null? l)
|
||||||
|
#f
|
||||||
|
(if (f x)
|
||||||
|
l
|
||||||
|
(memf x f (cdr l)))))])
|
||||||
|
memf))
|
||||||
|
|
||||||
(make-bootstrapped-primitive-code
|
(make-bootstrapped-primitive-code
|
||||||
'assq
|
'assq
|
||||||
'(letrec-values ([(assq) (lambda (x l)
|
'(letrec-values ([(assq) (lambda (x l)
|
||||||
|
@ -191,7 +210,24 @@
|
||||||
(car l)
|
(car l)
|
||||||
(assq x (cdr l)))))])
|
(assq x (cdr l)))))])
|
||||||
assq))
|
assq))
|
||||||
|
(make-bootstrapped-primitive-code
|
||||||
|
'assv
|
||||||
|
'(letrec-values ([(assv) (lambda (x l)
|
||||||
|
(if (null? l)
|
||||||
|
#f
|
||||||
|
(if (eqv? x (caar l))
|
||||||
|
(car l)
|
||||||
|
(assv x (cdr l)))))])
|
||||||
|
assv))
|
||||||
|
(make-bootstrapped-primitive-code
|
||||||
|
'assoc
|
||||||
|
'(letrec-values ([(assoc) (lambda (x l)
|
||||||
|
(if (null? l)
|
||||||
|
#f
|
||||||
|
(if (equal? x (caar l))
|
||||||
|
(car l)
|
||||||
|
(assoc x (cdr l)))))])
|
||||||
|
assoc))
|
||||||
(make-bootstrapped-primitive-code
|
(make-bootstrapped-primitive-code
|
||||||
'length
|
'length
|
||||||
'(letrec-values ([(length-iter) (lambda (l i)
|
'(letrec-values ([(length-iter) (lambda (l i)
|
||||||
|
|
|
@ -1244,7 +1244,11 @@
|
||||||
[(list)
|
[(list)
|
||||||
(list? (Const-const knowledge))]
|
(list? (Const-const knowledge))]
|
||||||
[(pair)
|
[(pair)
|
||||||
(pair? (Const-const knowledge))])]
|
(pair? (Const-const knowledge))]
|
||||||
|
[(caarpair)
|
||||||
|
(let ([x (Const-const knowledge)])
|
||||||
|
(and (pair? x)
|
||||||
|
(pair? (car x))))])]
|
||||||
[else
|
[else
|
||||||
#f])]))
|
#f])]))
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
'box
|
'box
|
||||||
'list
|
'list
|
||||||
'pair
|
'pair
|
||||||
|
'caarpair
|
||||||
'any))
|
'any))
|
||||||
|
|
||||||
|
|
||||||
|
@ -102,6 +103,7 @@
|
||||||
'>=
|
'>=
|
||||||
'cons
|
'cons
|
||||||
'car
|
'car
|
||||||
|
'caar
|
||||||
'cdr
|
'cdr
|
||||||
'list
|
'list
|
||||||
'list?
|
'list?
|
||||||
|
@ -189,6 +191,9 @@
|
||||||
|
|
||||||
[(eq? prim 'car)
|
[(eq? prim 'car)
|
||||||
(list 'pair)]
|
(list 'pair)]
|
||||||
|
|
||||||
|
[(eq? prim 'caar)
|
||||||
|
(list 'caarpair)]
|
||||||
|
|
||||||
[(eq? prim 'cdr)
|
[(eq? prim 'cdr)
|
||||||
(list 'pair)]
|
(list 'pair)]
|
||||||
|
|
|
@ -460,4 +460,5 @@
|
||||||
[(eq? (member x L) #f) #f]
|
[(eq? (member x L) #f) #f]
|
||||||
[else #t]))
|
[else #t]))
|
||||||
|
|
||||||
(provide (rename-out [-member member]))
|
(provide (rename-out [-member member]
|
||||||
|
[-member member?]))
|
||||||
|
|
|
@ -1029,8 +1029,6 @@ EXPORTS['color-list->image'] =
|
||||||
pinholeY);
|
pinholeY);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
EXPORTS['image-width'] =
|
EXPORTS['image-width'] =
|
||||||
makePrimitiveProcedure(
|
makePrimitiveProcedure(
|
||||||
'image-width',
|
'image-width',
|
||||||
|
|
|
@ -79,6 +79,9 @@
|
||||||
|
|
||||||
[(car)
|
[(car)
|
||||||
(format "(~a).first" (first checked-operands))]
|
(format "(~a).first" (first checked-operands))]
|
||||||
|
|
||||||
|
[(caar)
|
||||||
|
(format "(~a).first.first" (first checked-operands))]
|
||||||
|
|
||||||
[(cdr)
|
[(cdr)
|
||||||
(format "(~a).rest" (first checked-operands))]
|
(format "(~a).rest" (first checked-operands))]
|
||||||
|
@ -164,6 +167,8 @@
|
||||||
(format "RT.isList")]
|
(format "RT.isList")]
|
||||||
[(pair)
|
[(pair)
|
||||||
(format "RT.isPair")]
|
(format "RT.isPair")]
|
||||||
|
[(caarpair)
|
||||||
|
(format "RT.isCaarPair")]
|
||||||
[(box)
|
[(box)
|
||||||
(format "RT.isBox")])])
|
(format "RT.isBox")])])
|
||||||
(format "RT.testArgument(M,~s,~a,~a,~a,~s)"
|
(format "RT.testArgument(M,~s,~a,~a,~a,~s)"
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
var isNatural = baselib.numbers.isNatural;
|
var isNatural = baselib.numbers.isNatural;
|
||||||
var isReal = baselib.numbers.isReal;
|
var isReal = baselib.numbers.isReal;
|
||||||
var isPair = baselib.lists.isPair;
|
var isPair = baselib.lists.isPair;
|
||||||
|
var isCaarPair = function(x) { return isPair(x) && isPair(x.first); };
|
||||||
var isList = baselib.lists.isList;
|
var isList = baselib.lists.isList;
|
||||||
var isVector = baselib.vectors.isVector;
|
var isVector = baselib.vectors.isVector;
|
||||||
var isString = baselib.strings.isString;
|
var isString = baselib.strings.isString;
|
||||||
|
@ -800,6 +801,7 @@
|
||||||
|
|
||||||
// Type predicates
|
// Type predicates
|
||||||
exports['isPair'] = isPair;
|
exports['isPair'] = isPair;
|
||||||
|
exports['isCaarPair'] = isCaarPair;
|
||||||
exports['isList'] = isList;
|
exports['isList'] = isList;
|
||||||
exports['isVector'] = isVector;
|
exports['isVector'] = isVector;
|
||||||
exports['isOutputPort'] = isOutputPort;
|
exports['isOutputPort'] = isOutputPort;
|
||||||
|
|
|
@ -361,13 +361,13 @@ box?
|
||||||
map
|
map
|
||||||
andmap
|
andmap
|
||||||
ormap
|
ormap
|
||||||
memq
|
memq
|
||||||
;; memv
|
memv
|
||||||
member
|
member
|
||||||
;; memf
|
memf
|
||||||
assq
|
assq
|
||||||
;; assv
|
assv
|
||||||
;; assoc
|
assoc
|
||||||
;; remove
|
;; remove
|
||||||
;; filter
|
;; filter
|
||||||
;; foldl
|
;; foldl
|
||||||
|
|
11
lang/posn.rkt
Normal file
11
lang/posn.rkt
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
#lang s-exp "kernel.rkt"
|
||||||
|
|
||||||
|
;; The posn struct for the teaching languages
|
||||||
|
(provide struct:posn make-posn posn? posn-x posn-y set-posn-x! set-posn-y!
|
||||||
|
posn #;(rename-out (posn posn-id)))
|
||||||
|
|
||||||
|
(struct posn (x y) #:mutable #:transparent)
|
||||||
|
|
||||||
|
;; We define a separate function so tha it has the
|
||||||
|
;; name `make-posn':
|
||||||
|
(define (make-posn x y) (posn x y))
|
|
@ -14,6 +14,7 @@
|
||||||
"private/shared.rkt"
|
"private/shared.rkt"
|
||||||
"check-expect/check-expect.rkt"
|
"check-expect/check-expect.rkt"
|
||||||
"bool.rkt"
|
"bool.rkt"
|
||||||
|
"posn.rkt"
|
||||||
(for-syntax racket/base))
|
(for-syntax racket/base))
|
||||||
|
|
||||||
;; Programs written in Whalesong will have tracing enabled by default.
|
;; Programs written in Whalesong will have tracing enabled by default.
|
||||||
|
@ -28,6 +29,7 @@
|
||||||
[my-define-struct define-struct])
|
[my-define-struct define-struct])
|
||||||
shared
|
shared
|
||||||
(all-from-out "bool.rkt")
|
(all-from-out "bool.rkt")
|
||||||
|
(all-from-out "posn.rkt")
|
||||||
(except-out (all-from-out "check-expect/check-expect.rkt")
|
(except-out (all-from-out "check-expect/check-expect.rkt")
|
||||||
run-tests)
|
run-tests)
|
||||||
|
|
||||||
|
|
|
@ -6,4 +6,4 @@
|
||||||
|
|
||||||
(provide version)
|
(provide version)
|
||||||
(: version String)
|
(: version String)
|
||||||
(define version "1.43")
|
(define version "1.44")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user