hashmaps can now be printed and keys deleted
This commit is contained in:
@@ -7,6 +7,16 @@
|
||||
(define-syntax (pe expr)
|
||||
`(print ',expr "evaluates to" ,expr))
|
||||
|
||||
(define the-empty-stream ())
|
||||
|
||||
(define (stream-null? s) (if s t ()))
|
||||
|
||||
(define-syntax (delay expr)
|
||||
`(,lambda () ,expr))
|
||||
|
||||
(define (force promise)
|
||||
(promise))
|
||||
|
||||
(define-syntax (when condition . body)
|
||||
:doc "Special form for when multiple actions should be done if a
|
||||
condition is true.
|
||||
|
||||
@@ -6,6 +6,34 @@
|
||||
|
||||
(define-syntax (pe expr) `(print ',expr "evaluates to" ,expr))
|
||||
|
||||
(define the-empty-stream ())
|
||||
|
||||
(define (stream-null? s) (if s t ()))
|
||||
|
||||
(define-syntax (delay expr) `(,lambda () ,expr))
|
||||
|
||||
(define (force promise) (promise))
|
||||
|
||||
(define (pair-stream oject expression) (pair object (delay expression)))
|
||||
|
||||
(define stream-first first)
|
||||
|
||||
(define (stream-rest stream) (force (rest stream)))
|
||||
|
||||
(define (stream-ref s n) (if (= n 0) (stream-first s) (stream-ref (stream-rest s) (- n 1))))
|
||||
|
||||
(define (stream-filter pred stream) (cond ((stream-null? stream) the-empty-stream) ((pred (stream-first stream)) (pair-stream (stream-first stream) (stream-filter pred (stream-rest stream)))) (else (stream-filter pred (stream-rest stream)))))
|
||||
|
||||
(define (stream-map proc s) (if (stream-null? s) the-empty-stream (pair-stream (proc (stream-first s)) (stream-map proc (stream-rest s)))))
|
||||
|
||||
(define (stream-for-each proc s) (if (stream-null? s) 'done (begin (proc (stream-first s)) (stream-for-each proc (stream-rest s)))))
|
||||
|
||||
(define (stream-enumerate-interval low high) (if (> low high) the-empty-stream (pair-stream low (stream-enumerate-interval (+ low 1) high))))
|
||||
|
||||
(define (prime? x) (define (prime-helper x k) (cond ((= x k) t) ((= (% x k) 0) ()) (else (prime-helper x (+ k 1))))) (cond ((= x 1) ()) ((= x 2) t) (else (prime-helper x 2))))
|
||||
|
||||
(define (a) (stream-first (stream-rest (stream-filter prime? (stream-enumerate-interval 10000 1020)))))
|
||||
|
||||
(define-syntax (when condition . body) :doc "Special form for when multiple actions should be done if a\ncondition is true.\n\n{{{example_start}}}\n(when (not ())\n (print "Hello ")\n (print "from ")\n (print "when!"))\n\n(when ()\n (print "Goodbye ")\n (print "World!"))\n{{{example_end}}}\n" (if (= (rest body) ()) `(if ,condition (unquote-splicing body) nil) `(if ,condition (begin (unquote-splicing body)) nil)))
|
||||
|
||||
(define-syntax (unless condition . body) :doc "Special form for when multiple actions should be done if a\ncondition is false." (if (= (rest body) ()) `(if ,condition nil (unquote-splicing body)) `(if ,condition nil (begin (unquote-splicing body)))))
|
||||
|
||||
@@ -848,6 +848,12 @@ proc load_built_ins_into_environment() -> void {
|
||||
hm_set(hm->value.hashMap, key, value);
|
||||
return Memory::nil;
|
||||
};
|
||||
define((hash-map-delete! hm key), "TODO") {
|
||||
fetch(hm, key);
|
||||
try assert_type(hm, Lisp_Object_Type::HashMap);
|
||||
hm_delete_object(hm->value.hashMap, key);
|
||||
return Memory::nil;
|
||||
};
|
||||
define((vector . args), "TODO") {
|
||||
fetch(args);
|
||||
Lisp_Object* ret;
|
||||
|
||||
+1
-1
Submodule src/ftb updated: 94ad64f6bb...9c5512b182
+9
-1
@@ -284,7 +284,15 @@ proc print(Lisp_Object* node, bool print_repr = false, FILE* file = stdout) -> v
|
||||
case (Lisp_Object_Type::Continuation): fputs("[continuation]", file); break;
|
||||
case (Lisp_Object_Type::CFunction): fputs("[C-function]", file); break;
|
||||
case (Lisp_Object_Type::Pointer): fputs("[pointer]", file); break;
|
||||
case (Lisp_Object_Type::HashMap): fputs("[hashmap]", file); break;
|
||||
case (Lisp_Object_Type::HashMap): {
|
||||
for_lisp_obj_hash_map (node->value.hashMap) {
|
||||
fputs(" ", file);
|
||||
print(key, true, file);
|
||||
fputs(" -> ", file);
|
||||
print((Lisp_Object*)value, true, file);
|
||||
fputs("\n", file);
|
||||
}
|
||||
} break;
|
||||
case (Lisp_Object_Type::String): {
|
||||
if (print_repr) {
|
||||
putc('\"', file);
|
||||
|
||||
Reference in New Issue
Block a user