Setting up hash items at once

Q&A's, tips, howto's
Locked
vetelko
Posts: 23
Joined: Thu Oct 13, 2016 4:47 pm

Setting up hash items at once

Post by vetelko »

Hi guys,
is it possible to set hash items at once in hash definition?

Code: Select all

;; this works
(define cities:cities)
(cities "ny" "new york")
(cities "sf" "san francisco")
(println (cities "sf"))

;; this not
(define cities:cities '(
    ("ny" "new york")
    ("sf" "san francisco")))

(println (cities "sf"))
newLISP v.10.7.6 64-bit on BSD IPv4/6 UTF-8 libffi

varbanov
Posts: 6
Joined: Mon Jul 01, 2013 1:33 pm
Location: Sofia, Bulgaria

Re: Setting up hash items at once

Post by varbanov »

Hi,

Try

Code: Select all

(define cities:cities)         ; creates the default functor
(cities '(("ny" "new york") ("sf" "san francisco")))        ; the functor adds the data
(cities)
s.v.

ralph.ronnquist
Posts: 228
Joined: Mon Jun 02, 2014 1:40 am
Location: Melbourne, Australia

Re: Setting up hash items at once

Post by ralph.ronnquist »

And you can of course combine it into a single phrase like

Code: Select all

((or (define cities:cities) cities)
  '(("ny" "new york")  ("sf" "san francisco")))
but it's not very intelligible.

Locked