[albatross-users] al-for / ListIterator question...

Frederick Polgardy Jr fred at polgardy.com
Wed Oct 19 00:29:53 EST 2005


I've done a bit of code-generation (in python, not in albatross), and what I 
usually do for separated lists is create some variable (called 'sep' or 
some such) initially assigned to the null string, and set it to a comma at 
the end of the loop:

sep = ''
for item in someList:
    print sep+item
    sep = ', '
for item in nextList:
    print sep+item
    sep = ', '

Doesn't even matter how many lists you're iterating through.

The logic should be easy enough to translate into albatross code.

HTH,
Fred

On Tuesday 18 October 2005 00:27, Cameron Blackwood wrote:
> Hi,
>
> Im using the albatross templater to generate C like code (actually,
> its real usable C code, but thats beside the point)
> something that i need some advice on.
>
> I have a list of functions with inputs and outputs and im trying to
> generate code that does something like:
>
>
> -----------------------------
> <al-for iter="ifun" expr="functions">
> <al-exec expr="f=ifun.value()">
>
> CALL_FUNCTION_<al-value expr="f.name">(
>   # input1 , input2 , input3 , ... , inputN (NOCOMMA)
>   <al-for iter="iarg" expr="f.inputs">
>   <al-exec expr="a=iarg.value()">
>       <al-value expr="a.arg_name" noescape>
>       <al-if expr="iarg.index()  < len(f.inputs)-1">,</al-if whitespace>
>   </al-for>
>
>   # if inputs and outputs then , to seperate
>   <al-if expr="len(f.inputs) >0">
>    <al-if expr="len(f.outputs) >0">
>      ,
>    <al-if>
>   <al-if>
>
>   # output1 , output2 , output3 , ... , outputN (NOCOMMA)
>   <al-for iter="oarg" expr="f.outputs">
>   <al-exec expr="a=oarg.value()">
>       <al-value expr="a.arg_name" noescape>
>       <al-if expr="oarg.index()  < len(f.outputs)-1">,</al-if whitespace>
>   </al-for>
>   )
>
> </al-for>
> -----------------------------
>
> to generate:
>
> CALL_FUNCTION_foo(
>   in1, in2, in3
>   ,
>   out1, out2
>   )
>
>
>
>
> But, for seperating arguments, the:
>
>       <al-if expr="oarg.index()  < len(f.outputs)-1">,</al-if whitespace>
>
> is ugly. I guess what im wanting is a oarg.has_next() or
> oarg.is_last() or oarg.is_final().
>
>
> The ways that I can think of to do it are:
>   * abuse pagesize:
>       <al-for iter="iarg" expr="f.inputs" pagesize="1">
>     combined with:
>       <al-if expr="oarg.has_nextpage()">,</al-if>
>
>   * write my own tag:
>     that might get around the need for the <al-exec
> expr="a=oarg.value()"> too, especially if combined with...
>
>   * put the 'is_last()' check into the actual objects
>
>
> Hmm. Advice welcome. :-)
>
>
> cheers,
> cam
>
> PS: I posted here about using albatross in the pyweek games contest..
> sadly I got to distracted with pygame/graphics issues to get very far.
> Oh well, next one is in feb ;)
>
>
> --
>  / `Rev Dr'   cam  at darkqueen.org            Roleplaying, virtual goth
> \ <   http://darkqueen.org        Poly, *nix, Python, C/C++, genetics,
> ATM  > \  [+61 3] 9809 1523[h]         skeptic, Evil GM(tm). Sysadmin for
> hire / ---------- Random Quote ----------
> "I'd crawl over an acre of 'Visual This++' and 'Integrated Development
> That' to get to gcc, Emacs, and gdb.  Thank you."
> (By Vance Petree, Virginia Power)
> _______________________________________________
> Albatross-users mailing list
> Albatross-users at object-craft.com.au
> https://www.object-craft.com.au/cgi-bin/mailman/listinfo/albatross-users



More information about the Albatross-users mailing list