On Wed, Jun 13, 2012 at 11:42 AM, Jose Mario Quintana
<jose.mario.quint...@gmail.com> wrote:
> I do not think I implemented a fixed point combinator either and I
> doubt it can really be done directly in J because verbs cannot take
> directly verbs as arguments, and adverbs or conjunctions cannot take
> directly adverbs or conjunctions (at least not anymore in the current
> standard implementation of J).  Nevertheless, indirect recursion can
> be implemented neatly as we found out and others before us.

I think the trick here is that in a lisp-like language being at the
front of certain lisps is "special".  It's special in much the way
that `:6 is special for gerunds or J's apply is special for named
verb's -- in a lisp-like language this special syntax signals that a
lambda needs to take action instead of being passive.

Hypothetically speaking, I think we could live with an analogy like "a
lambda in J is a gerund of a monadic verb" and build up a system in J
which is very like a lambda.  J's limitation where a monadic verb
takes only one argument is something of a sticking point.  But we
could solve that.  Using psuedo-lisp, instead of

((lambda (a b c) ...) A B C)

we would do something like this:

((((lambda (a b c) ...) A) B) C)

of course, if we were really writing in a lisp-like language that
would look more like:

((((lambda (a)
     (lambda (b)
       (lambda (c)
         ...))) A) B) C)

so ideally, I would use some name other than "lambda" for my variant
construct, but "lambda" is a nonsense word -- it's just an arbitrary
letter -- so it's hard to think of a suitably systematic variant.

So... code:

lambda=:3 :0
  if. 1=#;:y do.
    3 :((y,'=.y');<;._2]0 :0)`''
  else.
    (,<#;:y) Defer (3 :(('''',y,'''=.y');<;._2]0 :0))`''
  end.
)

Defer=:2 :0
  if. (_1 {:: m) <: #m do.
    v |. y;_1 }. m
  else.
    (y;m) Defer v`''
  end.
)

Note''
  single letter words which follow have meaning beyond
  this message and outside the J language.
  Search for "S combinator" for details and examples.
)

I=: lambda 'x'
  x
)

K=: lambda 'x y'
  y
)

S=: lambda 'x y z'
  (x`:6 z)`:6 y`:6 z
)

I think I got that right -- I tried finding examples, but people
discussing this system seem to be shy about using examples.

Anyways, here's an example of how to achieve the above identity gerund
I in terms of S and K:

   I`:6 'a'
a
   (((S`:6 K)`:6 K)`:6 K)`:6 'a'
a

Of course, we could have instead defined K this way:

K=: lambda 'x'
  I
)

But then the result of (((S`:6 K)`:6 K)`:6 K)`:6 would be I which
would defeat the point of implementing it without using I.

That said, note that S was not necessary here.  K`:6 K already
represents the same operation that I represents.

(Again, I am assuming I got the definitions correct -- if someone sees
any errors here, please let me know.)

Thanks,

-- 
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to