Re: Getl and maps behavior?
Hi Henrik, The main problem is that I need to be able to handle an arbitrary object and convert all Ts to true, and NILs to false in the JSON string. With the NILs we run into a problem, because a property value of NIL means that this property does not exist. So it can never be extracted from the object itself. To cover non-NIL properties, you could do (mapcar '((X) (or (pair X) (cons T X))) (getl Tst) ) Is there some other function/mechanism I could use instead? Hmm, not that I can think of at the moment. To solve the problem with the NILs, you'll have to keep a separate record of possible properties (as is done, for example, in the '+Entity' objects). Cheers, - Alex -- UNSUBSCRIBE: mailto:[EMAIL PROTECTED]
Re: Getl and maps behavior?
Maybe this is a non-issue when I think about it. I can think of two possibilities: 1) For some reason an +Entity object needs to be converted to JSON. 2) A key = value structure needs to be sent, in such a case a paired list would do the trick, ie: ((k1 . v1) (k2 v2)) = {k1: v1, k2: v2}. This is probably more preferable than an object when I think even more :-). So, I'll implement that and take a look at converting entity objects. /Henrik On Thu, Aug 21, 2008 at 3:02 PM, Alexander Burger [EMAIL PROTECTED]wrote: Hi Henrik, The main problem is that I need to be able to handle an arbitrary object and convert all Ts to true, and NILs to false in the JSON string. With the NILs we run into a problem, because a property value of NIL means that this property does not exist. So it can never be extracted from the object itself. To cover non-NIL properties, you could do (mapcar '((X) (or (pair X) (cons T X))) (getl Tst) ) Is there some other function/mechanism I could use instead? Hmm, not that I can think of at the moment. To solve the problem with the NILs, you'll have to keep a separate record of possible properties (as is done, for example, in the '+Entity' objects). Cheers, - Alex -- UNSUBSCRIBE: mailto:[EMAIL PROTECTED] --=_Part_31067_20121356.1219308350562 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline div dir=ltrMaybe this is a non-issue when I think about it. I can think of two possibilities:brbr1) For some reason an +Entity object needs to be converted to JSON.brbr2) A key =gt; value structure needs to be sent, in such a case a paired list would do the trick, ie: ((k1 . v1) (k2 quot;v2quot;)) =gt; {quot;k1quot;: v1, quot;k2quot;: quot;v2quot;}. This is probably more preferable than an object when I think even more :-).br brSo, I#39;ll implement that and take a look at converting entity objects.brbr/Henrikbrbrdiv class=gmail_quoteOn Thu, Aug 21, 2008 at 3:02 PM, Alexander Burger span dir=ltrlt;a href=mailto:[EMAIL PROTECTED][EMAIL PROTECTED]/agt;/span wrote:br blockquote class=gmail_quote style=border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;Hi Henrik,br div class=Ih2E3dbr gt; The main problem is that I need to be able to handle an arbitrary object andbr gt; convert all Ts to true, and NILs to false in the JSON string.br br /divWith the NILs we run into a problem, because a property value of NILbr means that this property does not exist. So it can never be extractedbr from the object itself.br br To cover non-NIL properties, you could dobr br nbsp; (mapcarbr nbsp; nbsp; nbsp;#39;((X) (or (pair X) (cons T X)))br nbsp; nbsp; nbsp;(getl Tst) )br div class=Ih2E3dbr br gt; Is there some other function/mechanism I could use instead?br br /divHmm, not that I can think of at the moment.br br To solve the problem with the NILs, you#39;ll have to keep a separatebr record of possible properties (as is done, for example, in the #39;+Entity#39;br objects).br br Cheers,br - Alexbr font color=#88--br UNSUBSCRIBE: mailto:a href=mailto:picolisp@software-lab.de;picolisp@software-lab.de/a?subject=Unsubscribebr /font/blockquote/divbr/div --=_Part_31067_20121356.1219308350562-- -- UNSUBSCRIBE: mailto:[EMAIL PROTECTED] ---
Re: Getl and maps behavior?
Hi Henrik, convert all Ts to true, and NILs to false in the JSON string. With the NILs we run into a problem, because a property value of NIL means that this property does not exist. So it can never be extracted from the object itself. maybe the js - picolisp mapping false - NIL is not the right thing to do here? There are things like undefined, null, (empty string), NaN (maybe too?) or false you could represent as NIL but then you lose information during conversion and cannot rebuild the js data back again exactly. To solve the problem with the NILs, you'll have to keep a separate record of possible properties (as is done, for example, in the '+Entity' objects). Or, you could create your own unique NIL which would be treated by picolisp as any other non-NIL value and interpret it yourself during picolisp - javascript conversion as false, for example. : (setq MyNIL (new)) (setq Tst (new)) (put Tst 'a hello) (put Tst 'b T) (put Tst 'c MyNIL) # swap false, null, undefined or even NIL for MyNIL (getl Tst) (mapcar '((X) (or (pair X) (cons T X))) (getl Tst) ) (prog (prin [) (for (I . X) (mapcar '((X) (or (pair X) (cons T X))) (getl Tst) ) (when ( 1 I) (prin , )) (prin (cdr X) : ) (cond ((== (car X) MyNIL) (prin false)) ((== (car X) T) (prin true)) (T (print (car X) (prin ])) - $519715527 : - $519715537 : - hello : - T : - $519715527 : - (($519715527 . c) b (hello . a)) : - (($519715527 . c) (T . b) (hello . a)) : [c: false, b: true, a: hello]- ] This is oversimplified version as there are lots of special cases in javascript to handle, e.g. you have to double-quote keys if they are negative numbers if I remember well: [-1: negative numbers as strings in key] Alex, why does getl return a list of (property-value . property-name) and not a list of (property-name . property-value)? Cheers, Tomas -- UNSUBSCRIBE: mailto:[EMAIL PROTECTED]
Re: Getl and maps behavior?
Thanks for the input Thomas but I think I will just go with paired lists instead, they are easier to manipulate with various list functions and should therefore be preferable to basic objects anyway. +Entity objects are on the list though. This is oversimplified version as there are lots of special cases in javascript to handle, e.g. you have to double-quote keys if they are negative numbers if I remember well: As far as I've been able to see any kind of key is double quoted in the json string (so that is what happens now), at least in the examples I've looked at. Now the question is, should we do basic objects when converting from json or paired lists. Basic objects are possible in that direction but that would then break with the rule of only accepting +Entity objects and paired lists for encoding. I don't know how a paired list vs a basic object compare when it comes to populating an +Entity object, any suggestions Alex? If an object is easier then that could motivate the decision to go for object when decoding and thus having different input and output formats. /Henrik On Fri, Aug 22, 2008 at 2:24 AM, Tomas Hlavaty [EMAIL PROTECTED] wrote: Hi Henrik, convert all Ts to true, and NILs to false in the JSON string. With the NILs we run into a problem, because a property value of NIL means that this property does not exist. So it can never be extracted from the object itself. maybe the js - picolisp mapping false - NIL is not the right thing to do here? There are things like undefined, null, (empty string), NaN (maybe too?) or false you could represent as NIL but then you lose information during conversion and cannot rebuild the js data back again exactly. To solve the problem with the NILs, you'll have to keep a separate record of possible properties (as is done, for example, in the '+Entity' objects). Or, you could create your own unique NIL which would be treated by picolisp as any other non-NIL value and interpret it yourself during picolisp - javascript conversion as false, for example. : (setq MyNIL (new)) (setq Tst (new)) (put Tst 'a hello) (put Tst 'b T) (put Tst 'c MyNIL) # swap false, null, undefined or even NIL for MyNIL (getl Tst) (mapcar '((X) (or (pair X) (cons T X))) (getl Tst) ) (prog (prin [) (for (I . X) (mapcar '((X) (or (pair X) (cons T X))) (getl Tst) ) (when ( 1 I) (prin , )) (prin (cdr X) : ) (cond ((== (car X) MyNIL) (prin false)) ((== (car X) T) (prin true)) (T (print (car X) (prin ])) - $519715527 : - $519715537 : - hello : - T : - $519715527 : - (($519715527 . c) b (hello . a)) : - (($519715527 . c) (T . b) (hello . a)) : [c: false, b: true, a: hello]- ] This is oversimplified version as there are lots of special cases in javascript to handle, e.g. you have to double-quote keys if they are negative numbers if I remember well: [-1: negative numbers as strings in key] Alex, why does getl return a list of (property-value . property-name) and not a list of (property-name . property-value)? Cheers, Tomas -- UNSUBSCRIBE: mailto:[EMAIL PROTECTED] --=_Part_44266_24757689.1219373194560 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline div dir=ltrbrThanks for the input Thomas but I think I will just go with paired lists instead, they are easier to manipulate with various list functions and should therefore be preferable to basic objects anyway. +Entity objects are on the list though.br brgt;gt; This is oversimplified version as there are lots of special cases inbr javascript to handle, e.g. you have to double-quote keys if they arebr negative numbers if I remember well:lt;lt;brbrAs far as I#39;ve been able to see any kind of key is double quoted in the json string (so that is what happens now), at least in the examples I#39;ve looked at.brbr Now the question is, should we do basic objects when converting from json or paired lists. Basic objects are possible in that direction but that would then quot;breakquot; with the rule of only accepting +Entity objects and paired lists for encoding. br brI don#39;t know how a paired list vs a basic object compare when it comes to populating an +Entity object, any suggestions Alex? If an object is easier then that could motivate the decision to go for object when decoding and thus having different input and output formats.br br/Henrikbrbrdiv class=gmail_quoteOn Fri, Aug 22, 2008 at 2:24 AM, Tomas Hlavaty span dir=ltrlt;a href=mailto:[EMAIL PROTECTED][EMAIL PROTECTED]/agt;/span wrote:brblockquote class=gmail_quote style=border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex; Hi Henrik,br div class=Ih2E3dbr gt;gt; convert all Ts to true, and NILs to false in the JSON string.br br gt; With the NILs we run into a problem, because a property value of NILbr gt; means that this property does not exist. So it can