Page 1 of 1

Hash-map e contexts

Posted: Thu Sep 09, 2021 3:16 pm
by cameyo
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? "

Re: Hash-map e contexts

Posted: Fri Sep 10, 2021 10:23 am
by ralph.ronnquist
1) a "hashmap" is a context without default functor, i.e.

Code: Select all

(and (context? S) (nil? (sym (term S) S nil))) 
2) using the symbol as functor results in its list if entries, i.e.

Code: Select all

(apply S)

Re: Hash-map e contexts

Posted: Fri Sep 10, 2021 10:25 am
by ralph.ronnquist
tried to edit, to wrap the sym term into an eval, but the server doesn't let me...

Re: Hash-map e contexts

Posted: Fri Sep 10, 2021 8:57 pm
by cameyo
Thank you. I'll do some tests.

Re: Hash-map e contexts

Posted: Sat Sep 18, 2021 10:14 am
by cameyo
More difficulties:
a context with functor and functions can be a hash-map too.

Re: Hash-map e contexts

Posted: Fri Jan 14, 2022 2:44 pm
by cameyo
This works for me:

Code: Select all

(define (hash? hash)
  (and (context? (evals hash))
       (not (list? (evals (sym (term hash) hash nil))))))
With "eval" instead of "evals" (to avoid "Internal server error")