newLISP Fan Club

Forum => newLISP in the real world => Topic started by: cameyo on September 09, 2021, 08:16:14 AM

Title: Hash-map e contexts
Post by: cameyo on September 09, 2021, 08:16:14 AM
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? "
Title: Re: Hash-map e contexts
Post by: rrq on September 10, 2021, 03:23:41 AM
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)
Title: Re: Hash-map e contexts
Post by: rrq on September 10, 2021, 03:25:49 AM
tried to edit, to wrap the sym term into an eval, but the server doesn't let me...
Title: Re: Hash-map e contexts
Post by: cameyo on September 10, 2021, 01:57:51 PM
Thank you. I'll do some tests.
Title: Re: Hash-map e contexts
Post by: cameyo on September 18, 2021, 03:14:11 AM
More difficulties:

a context with functor and functions can be a hash-map too.
Title: Re: Hash-map e contexts
Post by: cameyo on January 14, 2022, 06:44:02 AM
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")