Re: Getl and maps behavior?

2008-08-23 Thread Tomas Hlavaty
Hi Alex,

> Having list cells behave like variables (by referring to their CAR
> parts) is a very useful feature. Not only for properties, but also
> for other list structures.
>
>: (setq L (1 2 3 4 5 6 7 8 9))
>-> (1 2 3 4 5 6 7 8 9)
>
>: (nth L 6)   
>-> (6 7 8 9)
>
>: (inc (nth L 6) 100)
>-> 106
>
>: (set (nth L 9) 777)
>-> 777
>
>: L  
>-> (1 2 3 4 5 106 7 8 777)

ohh, I see now!  Thanks for your patience:-)

>> # convert xml "list" (as returned by xml function) to xml "symbol"
>> ...
>> # convert xml "symbol" to xml "list" (as consumed by xml function)
>> ...
>
> As I said, this might give surprising results if you by chance encounter
> symbols used somewhere else in the system. Try (getl 'select)!

If I try to convert 'select to XML, I get an error:

(setq X2 (new))
(put X2 'select 'select)
(xwrite X2)


!? (getl S)
((("@Obj" . "@X") . "@Lst") (@ unify (-> "@X")) ("@P" box (cdr (-> "@Lst"))) 
("@C" box (let L (car (-> "@Lst")) (setq L (or (mapcan "select" L) ("select" 
(car L) T))) (cons NIL L L))) (_gen "@Obj") (_sel)) -- Symbol expected
? 

which is completely fine because it is not a "valid" input for
sym2xml.  It is a bit like feeding the 'xml' function with invalid
XML, just get an error.  Well, I do not know how to convert

((("@Obj" . "@X") . "@Lst") (@ unify (-> "@X")) ("@P" box (cdr (-> "@Lst"))) 
("@C" box (let L (car (-> "@Lst")) (setq L (or (mapcan "select" L) ("select" 
(car L) T))) (cons NIL L L))) (_gen "@Obj") (_sel))

to XML so an error seems quite reasonable.

However, if I feed it with the example Henrik provided:

(class +Product +Entity)
(rel name (+Need +String))
(rel id (+Need +Number))
(rel descr (+String))

(setq Product (new '(+Product) 'name "PC" 'id 123))

(setq X (new))
(put X 'product Product)
(xwrite X)

I get an XML:



   PC
   123


I think that Henrik is basically aiming for similar thing, except his
output format is not XML but JSON.

> It always returns the _whole_ property list, and this may contain
> other irrelevant data (as, for example, also Pilog stores rules in
> symbol properties, and the debug environment file names and line
> numbers).

I think that storing these irrelevant data (or rather specific purpose
data) is the good thing about representing XML using symbols.  I can
easily add more helper properties to a symbol during a computation.
It might be more efficient working with lists, but maybe not so
convenient.  This would need an example though which I currently don't
have:-(

Cheers,

Tomas
-- 
UNSUBSCRIBE: mailto:[EMAIL PROTECTED]


Re: Getl and maps behavior?

2008-08-22 Thread Alexander Burger
Hi Tomas,

> Isn't it just because it was implemented this way?  I mean these
> functions could be implemented to behave the same way even if getl
> returned a list of (property-name . property-value) which in this case

Ah, there is a misunderstanding. I was not talking especially about
'getl', but about how properties are implemented in general. It is
important, IMHO, that they are of the form (value . key) internally.

'getl' simply returns the property list as it is.

Surely it would have been possible to have 'getl' return a list of (key
. value) pairs, but this would have involved an additional level of
'cons'ing, creating unnecessary garbage.


> :(put 'A 'counter 0)
> -> 0
> : (put 'A 'list (1 2 3 4))
> -> (1 2 3 4)
> : (getl 'A)
> -> (((1 2 3 4) . list) (0 . counter)) # currently
> -> ((list . (1 2 3 4)) (counter . 0)) # I would expect this?
> 
> Or, how is the order inside pairs for getl/putl important to these
> functions?

If you use those functions directly on the result of 'getl', yes. But
this was not the intention, and I think I never did it.

The interesting point is to apply these functions directly to the cells
of a property list as returned by 'prop' or '::', as described
previously as (inc (:: counter)) or (pop (:: list)).

Having list cells behave like variables (by referring to their CAR
parts) is a very useful feature. Not only for properties, but also for
other list structures.

   : (setq L (1 2 3 4 5 6 7 8 9))
   -> (1 2 3 4 5 6 7 8 9)

   : (nth L 6)   
   -> (6 7 8 9)

   : (inc (nth L 6) 100)
   -> 106

   : (set (nth L 9) 777)
   -> 777

   : L  
   -> (1 2 3 4 5 106 7 8 777)



> I see, you think it is more useful to search for a given value and I
> thought it was more useful to search for a given property (even though

This is available anyway, with 'get', ':' etc.


> How and what for would you use assoc in your example?

In fact, I never needed that ;-)

But for the matter of an example:

   : (mapc '((Key Val) (put 'A Key Val)) '(a b c d e f g) (1 2 3 4 5 6 7))
   -> 7

   : (show 'A)
   A NIL
  g 7
  f 6
  e 5
  d 4
  c 3
  b 2
  a 1
   -> A

   : (get 'A 'd)
   -> 4

   : (assoc 4 (getl 'A))
   -> (4 . d)


> Sometimes a list of (key . value) is needed (e.g. a list of attributes
> for xml function) and in those cases, if I use getl in my code, I need
> to "swap" car and cdr values which is rather inconvenient.

I think 'getl' is not as important or useful as you seem to assume. It
always returns the _whole_ property list, and this may contain other
irrelevant data (as, for example, also Pilog stores rules in symbol
properties, and the debug environment file names and line numbers).

'getl' was primarily intended as the counterpart to 'putl', allowing a
fast cloning of symbols, or aid in debugging.

For application-relevant data it is much more common to use explicit
association lists. Assoc-lists were also the motivation to use the above
structure for xml attributes. They are more flexible than property
lists, because you can control aspects like the order of their elements,
or how you search them (with 'assoc', 'asoq', 'find' etc). Property
lists change their order on a last-recently used schema.


> I was thinking about XML data binding, representing XML using symbols
> instead of lists and that was where getl surprized me.  It is not an
> issue though, just unexpected surprice;-)

I would say it is best to use symbols when you have well defined,
independent properties, and association lists when you need a whole list
for a given operation.

> # convert xml "list" (as returned by xml function) to xml "symbol"
> ...
> # convert xml "symbol" to xml "list" (as consumed by xml function)
> ...

As I said, this might give surprising results if you by chance encounter
symbols used somewhere else in the system. Try (getl 'select)!



> The advantage of this approach is that I can use all those property
> access functions instead of searching for elements & attributes in a

Searching with 'assoc' or 'asoq' is about as convenient as using 'put'
and 'get'. In addition, you can use the full set of list manipulation
functions on association lists, while with property lists you are
limited to the 'get' and 'put' function family, or need the overhead of
'getl' and 'putl'. This overhead is relatively large, as the whole
property list needs to be copied.

> list.  Also, other useful stuff could be added to a symbol
> representing an XML element, e.g. indices for accessing items of a
> list hold by a property in a specific order.

Here, too, I believe that (nested) lists structures are more powerful.
But it all depends, of course. It is always worth experimenting around a
little.

Cheers,
- Alex
-- 
UNSUBSCRIBE: mailto:[EMAIL PROTECTED]


Re: Getl and maps behavior?

2008-08-22 Thread Tomas Hlavaty
Hi Henrik,

sorry I am not following in your thread but I do not seem to be
getting all emails from the mailing list.  Is anybody experiencing
similar problem?

> 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.

You are right.

> 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.

> Can anyone see a scenario where the above way of getting the
> relations would not work?

I think (isa '+Relation (car Prop)) works if you use picolisp OO
concepts, it won't work in general for any object/symbol.

Restricting yourself that way can be convenient but not necessary.

> In any case, the above generates the correct output with
> {..."descr": false} at the end of the json string.

Why is "descr" as false?  Would not it be better to output:

{"name": "PC", "id": "123"}

What if you have a js gui field which validates its input and expects
true|false|undefined (as don't care or unspecified)?

Cheers,

Tomas
-- 
UNSUBSCRIBE: mailto:[EMAIL PROTECTED]


Re: Getl and maps behavior?

2008-08-22 Thread Tomas Hlavaty
Hi Alex,

> Most of all, a cell can be passed to functions that expect a variable
> 'var' argument, like 'set', 'inc', 'pop', and many more. This is also
> the reason for the property functions 'prop' and '::'.
>
>: (put 'A 'counter 0)
>-> 0
>
>: (put 'A 'list (1 2 3 4))
>-> (1 2 3 4)
>
>: (with 'A (inc (:: counter)))
>-> 1
>
>: (pop (prop 'A 'list))   
>-> 1
>
>: (show 'A)
>A NIL
>   list (2 3 4)
>   counter 1
>-> A

Isn't it just because it was implemented this way?  I mean these
functions could be implemented to behave the same way even if getl
returned a list of (property-name . property-value) which in this case
would be:

:(put 'A 'counter 0)
-> 0
: (put 'A 'list (1 2 3 4))
-> (1 2 3 4)
: (getl 'A)
-> (((1 2 3 4) . list) (0 . counter)) # currently
-> ((list . (1 2 3 4)) (counter . 0)) # I would expect this?

Or, how is the order inside pairs for getl/putl important to these
functions?

> Another reason is that a property list could be searched for a given
> value with 'assoc'.

I see, you think it is more useful to search for a given value and I
thought it was more useful to search for a given property (even though
there are other functions but they don't work with the list of
properties as a whole).

How and what for would you use assoc in your example?

What information would you get if you found that some property has a
given value and how/what for would you use this information?  Also,
values can be "random" from a programmer point of view as opposed to
keys (usually) and a few properties can have the same value; in that
case assoc fails to be useful:

: (assoc 0 '((0 . list) (0 . counter)))
-> (0 . list)


Sometimes a list of (key . value) is needed (e.g. a list of attributes
for xml function) and in those cases, if I use getl in my code, I need
to "swap" car and cdr values which is rather inconvenient.

Am I missing something?


I was thinking about XML data binding, representing XML using symbols
instead of lists and that was where getl surprized me.  It is not an
issue though, just unexpected surprice;-)

# convert xml "list" (as returned by xml function) to xml "symbol"
(de xml2sym (S X)
   (if S
  (let (E (car X) A (cadr X) B (cddr X) G (group B))
 (for H G
(let E2 (car H)
   (if (<= (length (cdr H)) 1)
  (for I (cdr H)
 (if (<= (length (cdr I)) 1)
(put S E2 (cadr I))
(put S E2 (xml2sym (new) (cons E2 I)
  (for I (cdr H)
 (if (<= (length (cdr I)) 1)
(put S E2 (conc (get S E2) (list (cadr I
(put S E2 (conc (get S E2)
(list (xml2sym (new) (cons E2 
I))
 S)
  (when X
 (let (R (new))
(put R (car X) (xml2sym (new) X))
R

# convert xml "symbol" to xml "list" (as consumed by xml function)
(de sym2xml (S)
   (let P (car (getl S))
  (_sym2xml (car P) (cdr P

(de _sym2xml (S E)
   (if (or (num? S) (not (getl S)))
  (list E NIL S)
  (let (N (get S '@@ns)
C (filter '((X) (not (pat? (cdr X (getl S))
A (filter '((X) (and (pat? (cdr X)) (<> '@@ns (cdr X (getl S)))
 (make
(link
   (if N (intern (pack N ': E)) E)
   (reverse
  (mapcar
 '((X) (cons (intern (pack (cdr (chop (cdr X) (car X)))
 A)))
(for I (reverse C)
   (if (lst? (car I))
  (for J (car I)
 (link (_sym2xml J (cdr I
  (link (_sym2xml (car I) (cdr I)

(de xload (F)
   (xml2sym NIL (in F (xml

(de xwrite (S)
   (xml? T) (xml (sym2xml S)))

(de xsave (F S)
   (out F (xwrite S)))

To see how it works, run something like:

(setq X (xload "my.xml"))
(show X) ...
(xsave "my2.xml" X)

The advantage of this approach is that I can use all those property
access functions instead of searching for elements & attributes in a
list.  Also, other useful stuff could be added to a symbol
representing an XML element, e.g. indices for accessing items of a
list hold by a property in a specific order.

Thanks,

Tomas
-- 
UNSUBSCRIBE: mailto:[EMAIL PROTECTED]


Re: Getl and maps behavior?

2008-08-22 Thread Alexander Burger
Hi Tomas,

> Alex, why does getl return a list of (property-value . property-name)
> and not a list of (property-name . property-value)?

There are some practical reasons for representing the elements of
property lists in such a way.

Most of all, a cell can be passed to functions that expect a variable
'var' argument, like 'set', 'inc', 'pop', and many more. This is also
the reason for the property functions 'prop' and '::'.

   : (put 'A 'counter 0)
   -> 0

   : (put 'A 'list (1 2 3 4))
   -> (1 2 3 4)

   : (with 'A (inc (:: counter)))
   -> 1

   : (pop (prop 'A 'list))   
   -> 1

   : (show 'A)
   A NIL
  list (2 3 4)
  counter 1
   -> A

Another reason is that a property list could be searched for a given
value with 'assoc'.

Cheers,
- Alex
-- 
UNSUBSCRIBE: mailto:[EMAIL PROTECTED]


Re: Getl and maps behavior?

2008-08-21 Thread Henrik Sarvell
This seems to be working:

(class +Product +Entity)
(rel name (+Need +String))
(rel id (+Need +Number))
(rel descr (+String))

(setq Product (new '(+Product) 'name "PC" 'id 123))

(encObj> '+Json Product)

Where encObj> is simply an on the fly conversion to a paired list:

(dm encObj> (O)
  (encPair> This
 (make
(mapc
   '((Prop)
   (when (isa '+Relation (car Prop))
  (let Key (cdr Prop)
 (link (cons Key (get O Key))
   (getl (car (type O)))

Can anyone see a scenario where the above way of getting the relations would
not work? In any case, the above generates the correct output with
{..."descr": false} at the end of the json string.

/Henrik

On Fri, Aug 22, 2008 at 9:46 AM, Henrik Sarvell <[EMAIL PROTECTED]> wrote:

>
> 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_45459_577592.1219386676309
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

This seems to be working:(class +Product 
+Entity)(rel name (+Need +String))(rel id (+Need +Number))(rel 
descr (+String))(setq Product (new '(+Product) 'name 
"PC" 'id 123))
    (encObj> '+Json Product)Where encObj> 
is simply an on the fly conversion to a paired list:(dm encObj> 
(O)  (encPair> This  (make 
    (mapc 
   
'((Prop)
  
 (when (isa '+Relation (car Prop)) 
 
 (let Key (cdr Prop) 

 (link (cons Key (get O Key)) 
   (getl (car 
(type O)))Can anyone see a scenario where the above way of getting 
the relations would not work? In any case, t

Re: Getl and maps behavior?

2008-08-21 Thread Henrik Sarvell
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

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:<[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 und

Re: Getl and maps behavior?

2008-08-21 Thread Tomas Hlavaty
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?

2008-08-21 Thread Henrik Sarvell
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

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./HenrikOn 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:mailto:picolisp@software-lab.de";>picolisp@software-lab.de?subject=Unsubscribe


--=_Part_31067_20121356.1219308350562--
-- 
UNSUBSCRIBE: mailto:[EMAIL PROTECTED]
---


Re: Getl and maps behavior?

2008-08-21 Thread Alexander Burger
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]


Getl and maps behavior?

2008-08-20 Thread Henrik Sarvell
The JSON encoder/decoder is almost finished, there is only one problem left.
In the encoding I use getl to get all the properties of an object, however
when some of them contain T or NIL I run into problems.

Just running this code illustrates the problem:

(setq Tst (new))
(put Tst 'a "hello")
(put Tst 'b T)
(put Tst 'c NIL)

(getl Tst)

The 'b property shows up but without a value. I suppose I could capture that
and act accordingly, but the c is not there at all. I tried maps too but I
get the same behavior.

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.

Is there some other function/mechanism I could use instead?

/Henrik

--=_Part_29864_15871798.1219296826936
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

The JSON encoder/decoder is almost finished, there is only one 
problem left. In the encoding I use getl to get all the properties of an 
object, however when some of them contain T or NIL I run into problems.
Just running this code illustrates the problem:(setq Tst 
(new))(put Tst 'a "hello")(put Tst 'b T)(put Tst 
'c NIL)(getl Tst)The 'b property shows up but without a 
value. I suppose I could capture that and act accordingly, but the c is not 
there at all. I tried maps too but I get the same behavior.
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.Is 
there some other function/mechanism I could use instead?/Henrik


--=_Part_29864_15871798.1219296826936--
-- 
UNSUBSCRIBE: mailto:[EMAIL PROTECTED]
---