Просмотр исходного кода

hashmaps can now be printed and keys deleted

master
Felix Brendel 6 лет назад
Родитель
Сommit
c80478a2cb
5 измененных файлов: 54 добавлений и 2 удалений
  1. +10
    -0
      bin/pre.slime
  2. +28
    -0
      bin/pre.slime.expanded
  3. +6
    -0
      src/built_ins.cpp
  4. +1
    -1
      src/ftb
  5. +9
    -1
      src/io.cpp

+ 10
- 0
bin/pre.slime Просмотреть файл

@@ -7,6 +7,16 @@
(define-syntax (pe expr) (define-syntax (pe expr)
`(print ',expr "evaluates to" ,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) (define-syntax (when condition . body)
:doc "Special form for when multiple actions should be done if a :doc "Special form for when multiple actions should be done if a
condition is true. condition is true.


+ 28
- 0
bin/pre.slime.expanded Просмотреть файл

@@ -6,6 +6,34 @@


(define-syntax (pe expr) `(print ',expr "evaluates to" ,expr)) (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 (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))))) (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)))))


+ 6
- 0
src/built_ins.cpp Просмотреть файл

@@ -848,6 +848,12 @@ proc load_built_ins_into_environment() -> void {
hm_set(hm->value.hashMap, key, value); hm_set(hm->value.hashMap, key, value);
return Memory::nil; 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") { define((vector . args), "TODO") {
fetch(args); fetch(args);
Lisp_Object* ret; Lisp_Object* ret;


+ 1
- 1
src/ftb

@@ -1 +1 @@
Subproject commit 94ad64f6bb3a91247e8266217a5a0ab3a93c5d11
Subproject commit 9c5512b1825ad838af7926587922f2083273a601

+ 9
- 1
src/io.cpp Просмотреть файл

@@ -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::Continuation): fputs("[continuation]", file); break;
case (Lisp_Object_Type::CFunction): fputs("[C-function]", 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::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): { case (Lisp_Object_Type::String): {
if (print_repr) { if (print_repr) {
putc('\"', file); putc('\"', file);


Загрузка…
Отмена
Сохранить