You are viewing a plain text version of this content. The canonical link for it is here.
Posted to rivet-dev@tcl.apache.org by Massimo Manghi <ma...@unipr.it> on 2013/04/24 12:29:28 UTC

Introducing dictionaries in form2.tcl

Hi everybody

 I know form2.tcl is Harald's baby, so I won't be messing with it
without his opinion/approval

I've been working with a few forms recently and I found myself creating
select input elements initialized with ordered lists of data associating
a key to a label to be displayed on the select

I thought that having the whole set of value-label pairs in a dictionary
would be a safe and apt way to do this. It's easy, straightforward, I
don't see side-effects and it would provide a more concise way to
initialize it. We maybe could introduce a new switch

 formname select -dictionary $dict_value

from which the whole set of configuration parameters could be deduced
(defaults would be passed in the constructor the way we do now)

  thoughts?

-- 
-- Massimo Manghi

Dipartimento di Neuroscienze
Unità di Biofisica e Fisica Sanitaria
via Volturno 39
43125 Parma

---------------------------------------------------------------------
To unsubscribe, e-mail: rivet-dev-unsubscribe@tcl.apache.org
For additional commands, e-mail: rivet-dev-help@tcl.apache.org


Re: Form manual page misses "select"

Posted by Massimo Manghi <mx...@apache.org>.
Yes I noticed that page omitted to introduce 'select' method in a formal way

  -- Massimo

On 04/24/2013 03:47 PM, Harald Oehlmann wrote:
> I just checked the form manual page:
> http://tcl.apache.org/rivet/manual2.1/form_package.html
>
> The method "select" is only contained in the example but not explained...
>
> Thank you,
> Harald
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: rivet-dev-unsubscribe@tcl.apache.org
> For additional commands, e-mail: rivet-dev-help@tcl.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: rivet-dev-unsubscribe@tcl.apache.org
For additional commands, e-mail: rivet-dev-help@tcl.apache.org


Form manual page misses "select"

Posted by Harald Oehlmann <ha...@elmicron.de>.
I just checked the form manual page:
http://tcl.apache.org/rivet/manual2.1/form_package.html

The method "select" is only contained in the example but not explained...

Thank you,
Harald

---------------------------------------------------------------------
To unsubscribe, e-mail: rivet-dev-unsubscribe@tcl.apache.org
For additional commands, e-mail: rivet-dev-help@tcl.apache.org


Re: Introducing dictionaries in form2.tcl

Posted by Harald Oehlmann <ha...@elmicron.de>.
Sorry, Massimo, I am writing toooo much.
Just do waht you want, if it is your use-case, just go !

Nevertheless, here are again my remarks:

Am 24.04.2013 15:12, schrieb Massimo Manghi:
> On 04/24/2013 02:01 PM, Harald Oehlmann wrote:
>>
>> Well, my baby ;-)
>> I just fixed bugs and security holes...
>>
> 
> the same for me about Rivet, still I consider it my baby after almost 6
> years...

At least, you have human babies too ;-)

> I have select inputs whose data are built from queries to a database.
> In the whole picture it would be nice if also the database interface
> could be able to return a dictionary. It doesn't change the basic facts
> about form, just provides a nice interface for passing parameters by
> value in a single object while keeping coherent the way they're handled
> in the code
> 
> select wn \
>  -dictionary [$dbobj dictionary "select key,value from table where..."]

so this replaces:
set d [$dbobj dictionary "select key,value from table where..."]
$f select wm -labels [dict keys $d] -values [dict values $d]

This is reasonable.

In this case, I would not call the parameter "-dictionary". I would
suggest by the name that it sets labels and values at the same time.
Anyway, it is not important, that it is a dictionary, for the outside,
it may be a list with alternating key,val pairs.

What about:
$f select wn \
    -vallabels [$dbobj dictionary "select key,value from table where..."]

I am not shure how "$dbobj dictionary" works, but IMHO the "values"
should be the dict keys and the "labels" should be the dict values.
But I am not shure on this.

Internally in the form package, I would not handle the -vallabels
parameter as a dict, but as a list.
There might be multiple labels with same values and multiple values with
same labels, no uniqueness in no direction.

The caller may decide to pass a dict.

As an extreme, we may propose for dicts:
$f select win -vallabels $d1
and
$f select win -labvalues $d2

In the first, the dict keys are the values, in the second they are the
labels.

------
Side note about data bases: I would prefer to get close to the format
given by tdbc. When "dict" is used as output, you get by
set ld [$db allrows -type dict "select key,val from table where..."]
This results in a list of dicts like that:
{key K1 val V1} {key K2 val V2}

------
Enjoy,
Harald

---------------------------------------------------------------------
To unsubscribe, e-mail: rivet-dev-unsubscribe@tcl.apache.org
For additional commands, e-mail: rivet-dev-help@tcl.apache.org


Re: Introducing dictionaries in form2.tcl

Posted by Massimo Manghi <ma...@unipr.it>.
On 04/24/2013 02:01 PM, Harald Oehlmann wrote:
> 
> Well, my baby ;-)
> I just fixed bugs and security holes...
> 

the same for me about Rivet, still I consider it my baby after almost 6
years...

> I like dictionaries everywhere so I am in favour to that.
> 
> Personally, I would prefer with a new start featuring:
> - a new load_variables which returns a dict and handles lists and
> scalars in  a more beautiful way. I don't like the "__X"-members to
> indicate "X" be a list.

you mean a replacement for 'load_response'? If it's a different name we
may well introduce a new Tcl command and call it load_variables (also
load_qs,load_post,load_all would be good, reproducing in the naming the
same difference var_qs,var_post and var have for single parameters)

> - A rewrite of form2 which uses dicts everywhere and does not require
> incrtcl. The use of dicts will simplify all places where are arrays used
> so far...
> 

argh, you're killing me on this, I developed an affection over Itcl
after all these years. I'm kidding, I did very good projects based on
Itcl, but it's OK if we move on to TclOO. Do you have something
different in mind?

> If a "dict-parameter way" is added, this adds an additional redundant
> parameter interface.
> 
> What is the definition ?
> 
> select wn -labels {L1 L2 L3} -values {V1 V2 V3}
> 
> will use dict:
> 
> set dP [dict create\
> 	-labels {L1 L2 L3} \
> 	-values {V1 V2 V3} ]
> 

 when several select are in a form it's disturbing that you have to
carry around several lists suggesting their association following
conventions in the naming while you could just enforce the mapping
value->label in a single dictionary.

I have select inputs whose data are built from queries to a database.
In the whole picture it would be nice if also the database interface
could be able to return a dictionary. It doesn't change the basic facts
about form, just provides a nice interface for passing parameters by
value in a single object while keeping coherent the way they're handled
in the code

select wn \
 -dictionary [$dbobj dictionary "select key,value from table where..."]

> and will be called:
> 
> select wn -dictionary $dP
> 
> which will be equivalent to:
> 
> select wn {*}$dP
> 

-- 
-- Massimo Manghi

Dipartimento di Neuroscienze
Unità di Biofisica e Fisica Sanitaria
via Volturno 39
43125 Parma

---------------------------------------------------------------------
To unsubscribe, e-mail: rivet-dev-unsubscribe@tcl.apache.org
For additional commands, e-mail: rivet-dev-help@tcl.apache.org


Re: Introducing dictionaries in form2.tcl

Posted by Harald Oehlmann <ha...@elmicron.de>.
Am 24.04.2013 12:29, schrieb Massimo Manghi:
> Hi everybody
> 
>  I know form2.tcl is Harald's baby, so I won't be messing with it
> without his opinion/approval
> 
> I've been working with a few forms recently and I found myself creating
> select input elements initialized with ordered lists of data associating
> a key to a label to be displayed on the select
> 
> I thought that having the whole set of value-label pairs in a dictionary
> would be a safe and apt way to do this. It's easy, straightforward, I
> don't see side-effects and it would provide a more concise way to
> initialize it. We maybe could introduce a new switch
> 
>  formname select -dictionary $dict_value
> 
> from which the whole set of configuration parameters could be deduced
> (defaults would be passed in the constructor the way we do now)
> 
>   thoughts?

Well, my baby ;-)
I just fixed bugs and security holes...

I like dictionaries everywhere so I am in favour to that.

Personally, I would prefer with a new start featuring:
- a new load_variables which returns a dict and handles lists and
scalars in  a more beautiful way. I don't like the "__X"-members to
indicate "X" be a list.
- A rewrite of form2 which uses dicts everywhere and does not require
incrtcl. The use of dicts will simplify all places where are arrays used
so far...

If a "dict-parameter way" is added, this adds an additional redundant
parameter interface.

What is the definition ?

select wn -labels {L1 L2 L3} -values {V1 V2 V3}

will use dict:

set dP [dict create\
	-labels {L1 L2 L3} \
	-values {V1 V2 V3} ]

and will be called:

select wn -dictionary $dP

which will be equivalent to:

select wn {*}$dP

Is this the idea ?

Thank you,
Harald

---------------------------------------------------------------------
To unsubscribe, e-mail: rivet-dev-unsubscribe@tcl.apache.org
For additional commands, e-mail: rivet-dev-help@tcl.apache.org