How to filter only the contexts that represent a hash-map?
Example:
(dolist (_el (symbols))
(if (context? (eval _el))
(println (eval _el) {} (length (eval _el)))))
; -> Class 2
; -> MAIN 0
; -> Tree 0
; -> demo 0
; -> myHash 0
(dolist (_el (symbols))
(if (and (context? (eval _el))
(not (= _el 'MAIN))
(not (= _el 'Tree))
(not (= _el 'Class)))
(println (eval _el) {} (eval-string (string "(" _el ")")))))
; -> demo ()
; -> myHash (("1" 1) ("20" 20) ("57" 57) ("59" 59) ("81" 81))
Is there a way that doesn't use "eval-string" to display / count the values of a context representing a hash-map? "
Hash-map e contexts
-
- Posts: 228
- Joined: Mon Jun 02, 2014 1:40 am
- Location: Melbourne, Australia
Re: Hash-map e contexts
1) a "hashmap" is a context without default functor, i.e.
2) using the symbol as functor results in its list if entries, i.e.
Code: Select all
(and (context? S) (nil? (sym (term S) S nil)))
Code: Select all
(apply S)
-
- Posts: 228
- Joined: Mon Jun 02, 2014 1:40 am
- Location: Melbourne, Australia
Re: Hash-map e contexts
tried to edit, to wrap the sym term into an eval, but the server doesn't let me...
Re: Hash-map e contexts
Thank you. I'll do some tests.
Re: Hash-map e contexts
More difficulties:
a context with functor and functions can be a hash-map too.
a context with functor and functions can be a hash-map too.
Re: Hash-map e contexts
This works for me:
With "eval" instead of "evals" (to avoid "Internal server error")
Code: Select all
(define (hash? hash)
(and (context? (evals hash))
(not (list? (evals (sym (term hash) hash nil))))))