lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


It was thus said that the Great Mark Hamburg once stated:
> Two somewhat independent and still vague thoughts:
> 
> 1. Reading left-to-right and the | args | expr syntax:
> 
> I've actually been finding myself wanting a pipe operator that would take
> the results of one expression and pass them to the next expression. At
> that level, all it does is allow one to avoid deep nesting. The natural
> tokens are probably either the | or >>.
> 
> Thus in a Unix-ish fashion we could write:
> 
> 	numbers | filter( odd ) | map( square )
> 
> Rather than:
> 
> 	map( square )( filter( odd ) ( numbers ) )

  I've felt that doing such lends itself mroe for coroutines than just a
series of expressions [1], such as something like (sorry I mangle coroutines
a bit---I don't have much experience with them in Lua):

	function conversion(transform)
	  local done,c

	  done,c = coroutine.resume()
	  repeat
	    c = transform(c)
	    coroutine.yield(c)
	    done,c = coroutine.resume()
	  until done
	end

	function rot(bias) ... end
	function striphtml() ... end
	
	input = io.open("input")
	output = io.open("output","w")
	
	input => conversion(toupper) 
	      => strip_html
	      => rot(13)
	      => conversion(tolower)
	      => rot(13)
	      => output

> Or, coming full circle, maybe | args | expr isn't short hand for creating
> functions but rather a syntax for creating expression trees.

  Or a pipeline of coroutines.  But that takes this in a different direction
than functional programming.

  -spc

[1]	http://boston.conman.org/2007/01/14.1
	http://boston.conman.org/2007/10/20.1