[racket] redefining primitives?
About a minute ago, Todd O'Bryan wrote:
> Is it possible to redefine primitives, like +, and then provide them
> to another module?
Here's a quick example that provides your two-argument only `+':
#lang racket
(require (rename-in racket [+ r+]))
(provide (except-out (all-from-out racket) r+)
+)
(define (+ x y) (r+ x y))
or
#lang racket
(provide (except-out (all-from-out racket) +)
(rename-out [my+ +]))
(define (my+ x y) (+ x y))
or
#lang racket
(provide (except-out (all-from-out racket) +)
(rename-out [my+ +]))
(define my+ ; make it have `+' as its printed name
(let* ([r+ +]
[+ (lambda (+ x y) (+ x y))])
+))
> If so, can you also undefine primitives? Like if I wanted to make a
> student language where + only accepted two arguments and the list
> function was unavailable, how could I do that?
Same as above, but add `list' to the `except-out'.
--
((lambda (x) (x x)) (lambda (x) (x x))) Eli Barzilay:
http://barzilay.org/ Maze is Life!