On Tue, Jul 21, 2009 at 8:51 AM, Samuel Tardieu<[email protected]> wrote:
> This may be because I don't like locals much, but I would have written
> "seq>google-geolocation" as:
>
> : seq>google-geolocation ( input -- geo )
>  first4 [ [ string>number ] bi@ ] 2dip <google-geolocation> ;
>

I do try to avoid the locals. So far I try to avoid locals first, and
avoid stack shuffling second.

Once in awhile though, I run into places where I have one thing, say a
sequence, and another thing, a tuple in this case. And the elements
need to transferred from one to another in some _arbitrary_ order and
with some _arbitrary_ conversions done on the elements.

In this case google says "code,accuracy,latitude,longitude". What I want is:

<google-geolocation>
code-as-number >>code
accuracy-as-number >>accuracy
latitude-as-string >>latitude
longitude-as-string >>longitude

The fact that the order and conversions happen to work out to [[ s>n ]
bi@ ] 2dip is not material to the problem.

In that case I fall back to my old ways and just match up the two sets
of slots with named variables.

Anyway, thanks for piping up. I think if I was smarter I might have
gone with something like: (completely untested)

first4
[
  [ string>number >>code ]
  [ string>number >>accuracy ]
  [ >>latitude ]
  [ >>longitude ]
] spread
<google-geolocation>

But I usually don't think that's quite right.

What I really wanted to do was zip the array with 4 quotations, call
them all and then do first4 <google-geolocation>.

--
Darrin

------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge  
This is your chance to win up to $100,000 in prizes! For a limited time, 
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize  
details at: http://p.sf.net/sfu/Challenge
_______________________________________________
Factor-talk mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to