[Python-ideas] explicitation lines in python ?
Daniel DELAY
danieldelay at gmail.com
Sun Jun 27 09:00:32 CEST 2010
Le 26/06/2010 05:26, Chris Rebert a écrit :
>> If we could explicitate
>>
> That's not a word.
>
Sorry that was a wrong translation of french word "expliciter"
(http://www.wordreference.com/fren/expliciter) wich means something like
to express or to describe with more details.
>> explicitation(s) line(s)
>>
> Again, not a word, and not a great name for this either, IMO.
>
Yes perhaps "refinement line" would be better as GVR noticed this
feature is named "refinement" in ABC.
> What do you mean, you can put them right next to each other, and even
> better, give the expression a meaningful name:
>
> def line2html(line):
> return ''.join( '<td>{}</td>'.format(cell) for cell in line)
> htmltable = ''.join( '<tr>{}</tr>'.format(line2html(line)) for line in table)
>
Yes that's a solution if this piece of code is run only once.
But if this piece of code is in a function (or a loop), your function
line2html will be redefined for each function call (or iteration), wich
is something I usually try to avoid.
> In other words, "where" clauses, à la Haskell (see
> http://www.haskell.org/tutorial/patterns.html section 4.5); just tweak
> the syntax from
>
> expr_involving_bar :
> bar : expr
>
> to
>
> expr_involving_bar where:
> bar = expr
>
Oh yes that seems to be the same feature.
> and the equals sign makes more sense anyway.
>
Equals sign make sense if you see that feature as a variable assigment,
but this would make more difficult to distinguish refinement lines from
classical indented lines.
I used ":" because I see that more like something equivalent to a {key:
value} substitution wich would be done before execution.
In fact there are several options about how refinement option could work
a) refinement as a code substitution :
In this option, refinement is just a syntactic sugar.
The refinement name ("htmlline" in my example) is replaced with the
refinement expression it means before execution of python code.
As "htmlline" dsappear from code at the time of execution, it will not
populate locals().
b) refinement as variable assignment.
In this option, the values of htmlline are really stored in a local
variable "htmlline", wich will remain in locals() after execution of
this line.
As "htmlline" is not intented to be used elsewhere in the code, I would
probably prefer option a), but the pure substitution option has a
disadvantage : when the refinement name "htmlline" appears twice or more
in the main line, the same expression is evaluated twice or more wich is
probably not what we want.
That's why I would in fact prefer a third option
c) a refinement expression is only evaluated once even if the refinement
name (ex: "htmlline") appears twice or more, but that name is not
published in locals().
Cheers
--
Daniel
More information about the Python-ideas
mailing list