[Omake] join function?

Erick Tryzelaar erickt at dslextreme.com
Sat Jan 6 23:34:34 PST 2007


Nick wrote:
> Oops I didn't explain clearly what I meant by concatenation.
> I apologize.
> The following ocaml code explains the join function better than I could.
>
> ----------- join.ml begins -----------------
> let rec join x y = match x, y with
>   | [], _ 
>   | _, [] -> []
>   | x :: xs, y :: ys -> (x ^ y) :: join xs ys
>
>
> let _ =
>   let result =
>     join ["a"; "b"; "c"; "d" ] [ ".x"; ".y"; ".w"; ".z"]
>   in
>     List.iter print_endline result
> ------------ join.ml ends ----------------

Ah, I got you now, my mistake. I don't believe omake has that 
functionality built in, so you'd currently have to provide it yourself 
with something like this:

zip(x, y) =
    i = 0
    result =
    while $(lt $i, $(min $(length $x, $y)))
        result = $(array
            $(result,
                $(array
                    $(nth $x, $i),
                    $(nth $y, $i)
                )
            )
        )
        i = $(add $i, 1)
    return $(result)

min(x, y) =
    if $(lt $x, $y)
        return $x
    else
        return $y

join(x, y) =
    return $(foreach $(fun a, b, $a$b), $(zip $x, $y))


(I'm having "while" to run in osh, it keeps throwing an arity error. 
Even if i copy the example from here: 
http://omake.metaprl.org/omake-base.html#chapter:base)

It'd be nice if we could get some of these functions into the stdlib. If 
we did that, I'd see if we could get zip to work over an arbitrary 
amount of inputs.


While we're talking about extending the stdlib, I'd also like a 
python-like range function added, as well as foreachi, in ocaml's iteri 
style of a function.

Then, while we're there, could we remove the "create-" from 
"create-map"? I don't think there'd be any conflict, and it would make 
it more orthogonal to $(array). to add to that, it'd be nice if the 
$(map) function could be used to extend maps

How can we call a function like array or the map, but not have any items 
in it initially? I'd like to be able to do something like this:

x = $(map b, 1) // python equivalent to {'b': '1'}
...
x = $(map $x, c, 5) // python equivalent to {'b': '1', 'c': '5'}


Finally, I ran into a case where it'd be nice to create zero length 
maps. Is there any way to do this, other than:

x. =
    extends $(Map)

?

It'd be nice if we had something like "$(map ())", but I don't see 
anything like that in the documentation.


Oh one last thing. I've found that with coding complicated functions, I 
can get a little overwhelmed with $()s, such as the zip from above. Did 
I miss anything that would make this a little more simple to work with?

-e


More information about the Omake mailing list