1
1
mirror of https://github.com/kanaka/mal.git synced 2024-09-19 09:38:28 +03:00

racket: add seq and string?

Issue #166
This commit is contained in:
Dov Murik 2016-02-15 14:27:47 -05:00
parent 4e6ae3b787
commit b8c4d0525d
2 changed files with 12 additions and 1 deletions

View File

@ -23,6 +23,12 @@
(vector-append (first a) (list->vector (rest a)))
(append (reverse (rest a)) (first a)))))
(define (seq obj)
(cond [(_nil? obj) nil]
[(_string? obj) (if (eq? 0 (string-length obj)) nil (map string (string->list obj)))]
[(_empty? obj) nil]
[else (_to_list obj)]))
;; Meta functions
(define (meta obj)
(cond [(malfunc? obj) (malfunc-meta obj)]
@ -53,6 +59,7 @@
'false? (lambda (x) (eq? x #f))
'symbol (lambda (s) (if (symbol? s) s (string->symbol s)))
'symbol? symbol?
'string? _string?
'keyword (lambda (s) (if (_keyword? s) s (_keyword s)))
'keyword? _keyword?
@ -98,6 +105,7 @@
'apply do_apply
'map (lambda (f s) (_to_list (_map f s)))
'conj conj
'seq seq
'meta meta
'with-meta with-meta

View File

@ -4,7 +4,7 @@
malfunc malfunc? malfunc-fn
malfunc-ast malfunc-env malfunc-params malfunc-macro? malfunc-meta
_partition _equal? _printf
nil _nil? _keyword _keyword?
nil _nil? _keyword _keyword? _string?
_to_list _sequential? _count _empty? _nth _first _rest _map
_assoc _dissoc _get
atom atom? atom-val set-atom-val!)
@ -62,6 +62,9 @@
(define (_keyword? k)
(and (string? k) (regexp-match? #px"^\u029e" k)))
;; Strings
(define (_string? s)
(and (string? s) (not (_keyword? s))))
;; Lists and vectors