I'm missing my foreach keys %hash... :(
Posted: Sat Aug 26, 2006 9:09 pm
Hi there, I want to use hash tables in newLisp,
Take for example this code (Python challenge ;)
This way I decoded the string, using a hash table for lookup, we have "context?" for checking existence, that's nice, but what about length or foreach operations?, I guess I'm missing something... :(
I have read the docs about the "context" thing, by the way.
Is not this a *weird* way to add hashes to the language? I read some posts than says earlier implementations of newLisp didn't have context before.
But I want to believe that I'm still trying to program "the perl, ruby, python way". Please tell me how is the newLip way to do this kind of simple things. Please.
(ex)
Take for example this code (Python challenge ;)
Code: Select all
;* http://www.pythonchallenge.com/pc/def/map.html
(setq input
(string
"g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc dmp.\n"
"bmgle gr gl zw fylb gq glcddgagclr ylb rfyr'q ufw rfgq rcvr gq qm jmle.\n"
"sqgle qrpgle.kyicrpylq() gq pcamkkclbcb. lmu ynnjw ml rfc spj."))
; Create table for decryption
(for (k 0 25)
(setq key (char (+ k (char "a"))))
(setq value (char (+ (% (+ k 2) 26) (char "a"))))
(context 'dic key value)
;;(println key " - " value)
)
(define (decrypt input table)
(setq len (length input))
(setq output "")
(for (k 0 (- len 1))
(setq key (char (char input k)))
(if (context? table key)
(setq output (string output (context table key)))
(setq output (string output key))
)
)
(setq return output)
)
(println (decrypt input dic))
(println (decrypt "map" dic))
I have read the docs about the "context" thing, by the way.
Is not this a *weird* way to add hashes to the language? I read some posts than says earlier implementations of newLisp didn't have context before.
But I want to believe that I'm still trying to program "the perl, ruby, python way". Please tell me how is the newLip way to do this kind of simple things. Please.
(ex)