guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Display on guile


From: Praveen D V
Subject: Re: Display on guile
Date: Thu, 5 Mar 2009 21:38:25 +0530

hi,

On Thu, Mar 5, 2009 at 8:17 PM, Linas Vepstas <address@hidden> wrote:
> 2009/3/5  <address@hidden>:
>> hi Group,
>>
>> I executed these commands..
>>
>> $ guile
>> guile> (define mc (cons 'a 'b))
>> guile> mc
>> (a . b)
>> guile> (define ml (list 1 2 mc))
>> guile> ml
>> (1 2 (a . b))
>> guile> (list mc 1 2 3)
>> ((a . b) 1 2 3)
>> guile> (define mh (make-hash-table 2))
>> guile> (hashq-create-handle! mh 'one mc)
>> (one a . b)
>> guile> (hashq-create-handle! mh 'two ml)
>> (two 1 2 (a . b))
>> guile> mh
>> #(((two 1 2 (a . b)) (one a . b)) ())

Small correction, just checked on my cygwin(on windows now), it prints as
#(((two 1 2 (a . b)) ((one a . b)))
Also, not sure of the last '()'.  Just a did a cut&paste, something went wrong.

>> guile> (use-modules (ice-9 pretty-print))
>> guile> (pretty-print mh)
>> #(((two 1 2 (a . b)) (one a . b)) ())
>> guile>
>>
>> I was expecting handle:'one of hash:mh to be printed in parens as
>> #(((two 1 2 (a . b)) (one (a . b))) ())
>
> According to your logic, you must have also been expecting
> #(((two (1 2 (a . b))) (one (a . b))) ())
>
> which is not what you wrote.

No, not at all.  All I was expecting(assumed), cons always
prints as "( x . y )".  Notice
1. In list it is printed as assumed; either first or last element.
2. In hash it prints as assumed; if it is not the first element in value.
If ml2 was created as
guile> (define ml2 (list mc 1 2))
guile> ml2
((a . b) 1 2)
and if ml2 was used as value in a hash
guile> (hashq-create-handle! mh 'one ml2)
guile>mh
#(((two 1 2 (a . b)) ((one (a . b) 1 2))))
Question remains same, why is the behavior different if value is 'cons'?

>> Why is behaviour of print for a hash different from others?
>> Am I missing anything?
>
> When I read the documentation, I see:
> Return the (key . value) pair for key in the given hash table. If key
> is not in table then create an entry for it with init as the value,
> and return that pair.
>
> Notice the dot between key and value, which means that
> hashq-create-handle! behaves like cons, and not like list;
> from your mail, it seems that you were expecting it to
> behave like list.

Hope I'm clear this time.

--regards, Paveen




reply via email to

[Prev in Thread] Current Thread [Next in Thread]