Cool. It feels similar to underscore (http://underscorejs.org/) which
has probably 1/10 of the ubiquity of jQuery which is still quite a
bit. It's the first library that probably comes to mind for many
people when it comes to 'make javascript more functional'.  It's very
approachable. I've also seen bilby.js (http://bilby.brianmckenna.org/)
thrown around - it's like haskell for javascript. It's a bit too
extreme for me.

I like that yours has similar method naming to J. If you wanted to,
you could also extend underscore to do that
http://underscorejs.org/#mixin

The chaining in yours is also implement in underscore (from the docs):

var stooges = [{name: 'curly', age: 25}, {name: 'moe', age: 21},
{name: 'larry', age: 23}];
var youngest = _.chain(stooges)
  .sortBy(function(stooge){ return stooge.age; })
  .map(function(stooge){ return stooge.name + ' is ' + stooge.age; })
  .first()
  .value();
=> "moe is 21"

Thanks for sharing

On Thu, Jan 23, 2014 at 4:23 PM, Raul Miller <[email protected]> wrote:
> Here's a gist of the current draft:  https://gist.github.com/anonymous/8587032
>
> I must admit that I do not have very extensive tests yet, and I may
> mistreat some edge cases. I am not sure if that matters. I'll paste my
> tiny "test suite" at the bottom of this message.
>
> Thanks,
>
> --
> Raul
>
> <html><head><title>tests for a.js</title></head>
> <body>
>   <pre id="out"></pre>
>   <script src="a.js"></script>
>   <script>
>  window.out= function(t) {
>  var log= document.getElementById('out');
>  log.innerHTML+= t;
>  return t;
>  }
>  function maintain(f) {
>  var r;
>  try {
>  r= f();
>  } catch (e) {
>   var t= f+' failed '+e;
> alert(out(t));
> r= A.one;
>  }
>  if ((r instanceof A) && 1 === r.DATA[0]) {out('.\n');} else {out(f+'
> failed '+r+'.\n');}
>  }
>  window.v123= A(3).indices().plus(1);
>  window.m1to9= A([3,3]).reshape(A(9).indices());
>  maintain(function(){return v123.times(2).match(A([2,4,6]))});
>  // maintain(function(){return v123.take(2).match(A([1,2]))});
>  maintain(function(){return
> m1to9.dot('plus','times')(m1to9).match(A([3,3],[15,18,21,42,54,66,69,90,111]))});
>  maintain(function(){return
> m1to9.dot('plus','times')(A([3,2],[1,2,1])).match(A([3,2],[5,3,17,15,29,27]))});
>  maintain(function(){return v123.dot('plus','times')(v123).match(A(14))});
>  maintain(function(){return v123.match(A([1,2,3]))});
>  maintain(function(){return v123.reduce('plus').match(A(6))});
>   </script>
> </body></html>
>
>
> On Thu, Jan 23, 2014 at 12:50 PM, Joe Bogner <[email protected]> wrote:
>> Raul, your library sounds interesting. Please share more if you can later.
>>
>> Coffeescript is a fun language. The lambda syntax and lack of braces
>> make it feel closer to the problem domain than native javascript. It
>> also makes it harder to shoot yourself in the foot. The debugging and
>> compilation has greatly improved over the years too. The compiler
>> throws useful errors with line numbers etc.
>>
>> I agree that toys are useful for learning. It's common in the land of
>> lisp to write a toy interpreter to better understand the language. I
>> did that too and found putting this one together a nice break
>>
>> On Thu, Jan 23, 2014 at 12:12 PM, Raul Miller <[email protected]> wrote:
>>> I've been building an vsapl-like javascript library. I want that so
>>> that I can code webgl without having to round-trip to jhs for minor
>>> array manipulation. It's pretty simple since I only support one
>>> numeric type (javascript numbers) in the arrays. So basically it's a
>>> functional object library with a shape/data pair representing an array
>>> - so for webgl arrays I basically can just extract the data and use it
>>> "as-is".  (I say "functional object library" because I use a
>>> javascript object to represent each array, and monadic functions are
>>> niladic methods ("this" is the right argument) which return a new
>>> array while dyadic functions are single argument methods which also
>>> return a new array ("this" is the left argument). Or at least, that's
>>> how I currently have it wired up.)
>>>
>>> I'm not using git for my versioning, yet, because it's so trivial I
>>> work better at this stage with a file for each version.  I should
>>> probably just stop working on it, and get back to coding webgl, but
>>> coffeescript looks fun and I would like to compare code size and
>>> simplicity between a native javascript implementation and a
>>> coffeescript implementatin).
>>>
>>> I am using the vsapl semantics because they seem simpler to implement
>>> for the subset of functionality I need (numeric operations on small
>>> arrays, when using javascript) than the full J semantics. Also,
>>> browsers have intentionally crippled functionality so any significant
>>> use of the library would want jhs for heavy lifting.
>>>
>>> Anyways, toys are good for learning, and I've been struggling with
>>> concepts of what I should be doing that's worthwhile for other people,
>>> and if nothing else, this is a sometimes relaxing effort.
>>>
>>> Thanks,
>>>
>>> --
>>> Raul
>>>
>>>
>>> On Thu, Jan 23, 2014 at 11:56 AM, Joe Bogner <[email protected]> wrote:
>>>> Thanks for the feedback. I just added in the insert adverb and pushed
>>>> the code. It makes it feel more like APL now since I can do the
>>>> prototypical +/1,2,3,4.
>>>>
>>>> Implementing forks might be up next (fun). Then I can do the J "hello
>>>> world" of (+/%#) 5,10,15
>>>>
>>>> On Thu, Jan 23, 2014 at 11:41 AM, Raul Miller <[email protected]> 
>>>> wrote:
>>>>> I like this, and I think it is time I learn coffeescript. This relates
>>>>> to some other efforts of mine.
>>>>>
>>>>> Thank you,
>>>>>
>>>>> --
>>>>> Raul
>>>>>
>>>>>
>>>>> On Thu, Jan 23, 2014 at 11:20 AM, John Baker <[email protected]> wrote:
>>>>>> Interesting. I don't know cofffescript but it's not hard to figure out
>>>>>> what's going on here.
>>>>>>
>>>>>>
>>>>>> On Wed, Jan 22, 2014 at 9:22 PM, Joe Bogner <[email protected]> wrote:
>>>>>>
>>>>>>> I ported Arthur Whitney's one page APL interpreter fragment[1] to
>>>>>>> coffeescript (which enables it to run in javascript) as learning
>>>>>>> exercise.
>>>>>>>
>>>>>>> http://csilo.com/dev/apljs.html
>>>>>>>
>>>>>>> code is here: https://github.com/joebo/apl-js/blob/master/apl.coffee
>>>>>>>
>>>>>>> This could be extended to create in-browser games/learning exercises.
>>>>>>> Of course, it would also make sense to change the symbols to J. I kept
>>>>>>> the original ones for historical reasons for now.
>>>>>>>
>>>>>>> [1] - http://www.jsoftware.com/jwiki/Essays/Incunabulum
>>>>>>> [2] - http://www.jsoftware.com/papers/AIOJ/AIOJ.htm
>>>>>>> ----------------------------------------------------------------------
>>>>>>> For information about J forums see http://www.jsoftware.com/forums.htm
>>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> --
>>>>>> John D. Baker
>>>>>> [email protected]
>>>>>> ----------------------------------------------------------------------
>>>>>> For information about J forums see http://www.jsoftware.com/forums.htm
>>>>> ----------------------------------------------------------------------
>>>>> For information about J forums see http://www.jsoftware.com/forums.htm
>>>> ----------------------------------------------------------------------
>>>> For information about J forums see http://www.jsoftware.com/forums.htm
>>> ----------------------------------------------------------------------
>>> For information about J forums see http://www.jsoftware.com/forums.htm
>> ----------------------------------------------------------------------
>> For information about J forums see http://www.jsoftware.com/forums.htm
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to