Discussion:
using a zip as a sequence?
Paul Dufresne
2005-10-26 03:04:26 UTC
Permalink
I tend to think this is a bug:
goo/user 0<= (set myzip (zip #[ 1 2 3 4] #[ 5 6 7 8] ) )
goo/user 0=> #{<zip> zip-dat: #(#[1 2 3 4] #[5 6 7 8])}
goo/user 0<= (1st myzip)
ERROR: No applicable methods on #{Gen elt-or ((x <col>) (k <any>)
(default <any>))} when called with (#{<zip> zip-dat: #(#[1 2 3 4] #[5 6
7 8])} 0 #{<elt-default>}).
Type ",restart N" to restart execution:
Is it?
--
http://www.fastmail.fm - Choose from over 50 domains or use your own
Jonathan Bachrach
2005-10-26 21:00:19 UTC
Permalink
this is a bug and while debugging it i found other problems with zip.
here's the new zip.goo file that should fix it. let me know.

(use goo/cols/col)
(use goo/cols/seq)

(exported
(dc <zip> (<seq>))
(dg zip (e|... => <zip>))
(dg unzip (z|<zip> => <tup>)))

(dp zip-dat (<zip> => <tup>) #())

(dm zip (e|... => <zip>)
(new <zip> zip-dat (as <tup> e)))

(dm unzip (z|<zip> => <tup>)
(zip-dat z))

(dc <zip-state> (<any>))

(dp zip-states (<zip-state> => <tup>))

(dc <zip-enum> (<enum>))

(dp! %enums (<zip-enum> => <tup>))

(dm enum (x|<zip> => <zip-enum>)
(new <zip-enum> %enums (map enum (zip-dat x))))

(dm fin? (e|<zip-enum> => <log>)
(any? fin? (%enums e)))

(dm nxt (e|<zip-enum> => <zip-enum>)
(renew e %enums (map nxt (%enums e))))

(dm now (e|<zip-enum> => <any>)
(map now (%enums e)))

(dm now-setter (v|<zip> e|<zip-enum>)
(for ((ve v) (ee (%enums e))) (set (now ee) (now ve))))

(dm now-key (e|<zip-enum> => <zip>)
(map now-key (%enums e)))

(dm elt-or (x|<zip> key|<int> default => <any>)
(rep fnd (((count <int>) 0) ((e <zip-enum>) (enum x)))
(if (fin? e)
default
(if (== count key)
(now e)
(fnd (+ count 1) (nxt e))))))
Post by Paul Dufresne
goo/user 0<= (set myzip (zip #[ 1 2 3 4] #[ 5 6 7 8] ) )
goo/user 0=> #{<zip> zip-dat: #(#[1 2 3 4] #[5 6 7 8])}
goo/user 0<= (1st myzip)
ERROR: No applicable methods on #{Gen elt-or ((x <col>) (k <any>)
(default <any>))} when called with (#{<zip> zip-dat: #(#[1 2 3 4] #[5 6
7 8])} 0 #{<elt-default>}).
Is it?
Paul Dufresne
2005-10-26 23:36:52 UTC
Permalink
I have had to put back:
(use goo/boot)
(use goo/fun)
(use goo/class)
(use goo/macros)
(use goo/types)
(use goo/math)
at the beginning because exported was unknown.
This is probably too much to fix this but...

(1st myzip) now works, but I still cannot map a function over a zip:

goo/user 0<= (use /home/paul/zip.goo)
[Loading module /home/paul/zip.goo...
]
warning: 'unzip' from /home/paul/zip.goo clobbers local binding.
warning: '<zip>' from /home/paul/zip.goo clobbers local binding.
warning: 'zip' from /home/paul/zip.goo clobbers local binding.
goo/user 0=> #f
goo/user 0<= (set myzip (zip #(1 2 3 4) #( 5 6 7 8) ) )
goo/user 0=> #{<zip> zip-dat: #(#(1 2 3 4) #(5 6 7 8))}
goo/user 0<= (1st myzip)
goo/user 0=> #(1 5)
goo/user 0<= (snd myzip)
ERROR: Unbound variable snd.
Type ",restart N" to restart execution:
1. Return to interpreter level 1.
2. Return to interpreter level 0.
3. Exit the top-level interpreter.
goo/user 1<= (2nd myzip)
goo/user 1=> #(2 6)
goo/user 1<= (set myfun (fun (x) x))
goo/user 1=> #{Met ((x <any>))}
goo/user 1<= (map myfun #( 4 5 6) )
goo/user 1=> #(4 5 6)
goo/user 1<= (map myfun myzip)
ERROR: No applicable methods on #{Gen fab ((t #{T< <col>}) (s <int>) =>
<col>)} when called with (#{Class <zip> (<seq>)} 4).
Type ",restart N" to restart execution:
--
http://www.fastmail.fm - Same, same, but differentÂ…
Loading...