Setting up hash items at once

Q&A's, tips, howto's

Setting up hash items at once

Postby vetelko » Tue Aug 15, 2017 9:39 am

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.4 64-bit on OpenBSD IPv4/6 UTF-8 libffi
vetelko
 
Posts: 20
Joined: Thu Oct 13, 2016 4:47 pm

Re: Setting up hash items at once

Postby varbanov » Fri Aug 18, 2017 8:19 am

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.
varbanov
 
Posts: 6
Joined: Mon Jul 01, 2013 1:33 pm
Location: Sofia, Bulgaria

Re: Setting up hash items at once

Postby ralph.ronnquist » Fri Aug 18, 2017 10:38 pm

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.
ralph.ronnquist
 
Posts: 178
Joined: Mon Jun 02, 2014 1:40 am
Location: Melbourne, Australia


Return to newLISP in the real world

Who is online

Users browsing this forum: No registered users and 2 guests

cron