Hash-map e contexts

Started by cameyo, September 09, 2021, 08:16:14 AM

Previous topic - Next topic

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? "

rrq

#1
1) a "hashmap" is a context without default functor, i.e.
(and (context? S) (nil? (sym (term S) S nil)))

2) using the symbol as functor results in its list if entries, i.e.
(apply S)

rrq

#2
tried to edit, to wrap the sym term into an eval, but the server doesn't let me...

cameyo

#3
Thank you. I'll do some tests.

cameyo

#4
More difficulties:

a context with functor and functions can be a hash-map too.

cameyo

#5
This works for me:
(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")