unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Display on guile
@ 2009-03-05  8:05 for.pdv
  2009-03-05 14:47 ` Linas Vepstas
  0 siblings, 1 reply; 6+ messages in thread
From: for.pdv @ 2009-03-05  8:05 UTC (permalink / raw)
  To: guile-user

[-- Attachment #1: Type: text/plain, Size: 716 bytes --]

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)) ())
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))) ())

Why is behaviour of print for a hash different from others?
Am I missing anything?

--regards, Praveen

[-- Attachment #2: Type: text/html, Size: 957 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Display on guile
  2009-03-05  8:05 Display on guile for.pdv
@ 2009-03-05 14:47 ` Linas Vepstas
  2009-03-05 16:08   ` Praveen D V
  0 siblings, 1 reply; 6+ messages in thread
From: Linas Vepstas @ 2009-03-05 14:47 UTC (permalink / raw)
  To: for.pdv; +Cc: guile-user

2009/3/5  <for.pdv@gmail.com>:
> 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)) ())
> 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.

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

--linas




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Display on guile
  2009-03-05 14:47 ` Linas Vepstas
@ 2009-03-05 16:08   ` Praveen D V
  2009-03-05 16:11     ` Praveen D V
  2009-03-05 18:27     ` Linas Vepstas
  0 siblings, 2 replies; 6+ messages in thread
From: Praveen D V @ 2009-03-05 16:08 UTC (permalink / raw)
  To: linasvepstas; +Cc: guile-user

hi,

On Thu, Mar 5, 2009 at 8:17 PM, Linas Vepstas <linasvepstas@gmail.com> wrote:
> 2009/3/5  <for.pdv@gmail.com>:
>> 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




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Display on guile
  2009-03-05 16:08   ` Praveen D V
@ 2009-03-05 16:11     ` Praveen D V
  2009-03-05 18:27     ` Linas Vepstas
  1 sibling, 0 replies; 6+ messages in thread
From: Praveen D V @ 2009-03-05 16:11 UTC (permalink / raw)
  To: linasvepstas; +Cc: guile-user

On Thu, Mar 5, 2009 at 9:38 PM, Praveen D V <for.pdv@gmail.com> wrote:
> hi,
>
> On Thu, Mar 5, 2009 at 8:17 PM, Linas Vepstas <linasvepstas@gmail.com> wrote:
>> 2009/3/5  <for.pdv@gmail.com>:
>>> 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.

Please read it as "In hash it prints as assumed; if it is not the ONLY
member 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
>




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Display on guile
  2009-03-05 16:08   ` Praveen D V
  2009-03-05 16:11     ` Praveen D V
@ 2009-03-05 18:27     ` Linas Vepstas
  2009-03-10  3:41       ` for.pdv
  1 sibling, 1 reply; 6+ messages in thread
From: Linas Vepstas @ 2009-03-05 18:27 UTC (permalink / raw)
  To: Praveen D V; +Cc: guile-user

2009/3/5 Praveen D V <for.pdv@gmail.com>:

> Hope I'm clear this time.

I hope I am too:

guile> (define x (cons 'c 'd))
guile> x
(c . d)
guile> (define y (cons 'b x))
guile> y
(b c . d)
guile> (define z (cons 'a y))
guile> z
(a b c . d)

--linas




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Re: Display on guile
  2009-03-05 18:27     ` Linas Vepstas
@ 2009-03-10  3:41       ` for.pdv
  0 siblings, 0 replies; 6+ messages in thread
From: for.pdv @ 2009-03-10  3:41 UTC (permalink / raw)
  To: Linas Vepstas, guile-user

[-- Attachment #1: Type: text/plain, Size: 824 bytes --]

hi,

Oh.. okay. I completely forgot about the printing of immediates vs  
non-immediates.

guile> mh
#(((two 1 2 (a . b))) ((one a . b)))
guile> (define kv (hash-get-handle mh 'one))
guile> kv
(one a . b)
guile> mc
(a . b)
guile> kv
(one a . b)
guile> (set-cdr! kv (cons mc '()))
guile> kv
(one (a . b))
guile> mh
#(((two 1 2 (a . b))) ((one (a . b))))
guile> (pair? kv)
#t
guile> (pair? (cdr kv))
#t
guile> (list? (cdr kv))
#t

I understand it now.

--regards, Praveen

On Mar 5, 2009 11:57pm, Linas Vepstas <linasvepstas@gmail.com> wrote:
> 2009/3/5 Praveen DV for.pdv@gmail.com>:



> > Hope I'm clear this time.



> I hope I am too:



> guile> (define x (cons 'c 'd))

> guile> x

> (c . d)

> guile> (define y (cons 'bx))

> guile> y

> (bc . d)

> guile> (define z (cons 'ay))

> guile> z

> (abc . d)



> --linas


[-- Attachment #2: Type: text/html, Size: 1377 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2009-03-10  3:41 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-03-05  8:05 Display on guile for.pdv
2009-03-05 14:47 ` Linas Vepstas
2009-03-05 16:08   ` Praveen D V
2009-03-05 16:11     ` Praveen D V
2009-03-05 18:27     ` Linas Vepstas
2009-03-10  3:41       ` for.pdv

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).