Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^2: A mini-language for sequences (part 1)

by tmoertel (Chaplain)
on Nov 06, 2004 at 16:03 UTC ( #405772=note: print w/replies, xml ) Need Help??


in reply to Re: A mini-language for sequences (part 1)
in thread A mini-language for sequences (part 1)

One thing I forgot to point out in my previous response is that the example you cite, in particular, is crippled by the small size of our vocabulary (to date). Had we the space to discuss concatmap, the following implementation would have been available:
seq_from_spec( \(@site1, @site2) ) ->seq_concatmap( sub { seq_zip(map seq(split//), @_) } ) ->seq_foreach( sub { $counts{"@_"}++ } );
This implementation is much clearer (assuming you know concatmap).

Concatmap combines concat and map; it maps a sequence to a sequence of sequences, whose values are then concatenated to yield the output sequence. For example:

sub upto { 1 .. $_[0] } sub supto { seq(upto(@_)); } seq(1..3) -> seq_map(\&upto) -> enumerate; # 0 => 1 # 1 => 1 2 # 2 => 1 2 3 seq(1..3) -> seq_map(\&supto) -> seq_concat -> enumerate; # 0 => 1 # 1 => 1 # 2 => 2 # 3 => 1 # 4 => 2 # 5 => 3 seq(1..3) -> seq_concatmap(\&supto) -> enumerate; # 0 => 1 # 1 => 1 # 2 => 2 # 3 => 1 # 4 => 2 # 5 => 3

Cheers,
Tom

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://405772]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (10)
As of 2019-09-16 16:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The room is dark, and your next move is ...












    Results (196 votes). Check out past polls.

    Notices?