Linda,

There is a general rule that should be followed in J programs: Don't use x
or y as a global name. The names x, y, m, n, u and v are kind of special.
You can use them for global names but you may not be able to see their
global values in explicit definitions as they are shadowed by local names.

The use of "names" probably isn't doing what you think it is. The right
argument is supposed to be a number to select the type of names to list.
The letter "x" just passes through. But it can be used to illustrate a
problem when using y as a global name.

   a=:1
   aa=:2
   y=:3
   yy=:4
   names''
a  aa yy

What happened to "y"?

"names" uses the explicit verb "nl" to build the list. Since nl is explicit
x and y always exist. Therefore nl removes the names from the return to
avoid confusion. The verb "l" below is tacit and does not create local y.
Therefore it is visible and can be accessed. But don't let this fool you
into thinking that you can get to y simply by using a tacit definition. You
need to be aware when a definition executes.

   l=:4!:1
   l 0
+-+--+-+--+
|a|aa|y|yy|
+-+--+-+--+

There is y.

Your anonymous verb (13 :'x + 10*y') is tacit so no local x or y is
defined. Had you defined it as (4 :'x + 10*y') then local x and y would
exist; however, they are local and disappear when the verb completes.


On Mon, Jan 2, 2012 at 9:18 AM, Linda Alvord <lindaalv...@verizon.net>wrote:

> Now I have a new problem:
>
>   why=: 13 :'x + 10*y'/|. 1 2 3 4 5
>   erase names 'x'
> 1
>   why
> 12345
>   x
> |value error: x
>
> What is  x  in  why ?
>
> -----Original Message-----
> From: programming-boun...@jsoftware.com
> [mailto:programming-boun...@jsoftware.com] On Behalf Of Aai
> Sent: Monday, January 02, 2012 5:42 AM
> To: Programming forum
> Subject: Re: [Jprogramming] Binary representation without #: or #.
>
>
>
> On 02-01-12 11:21, Linda Alvord wrote:
> > This was a while ago, but how about a simple J version:
> >
> >     brila=: 13 :'([:(++:)/|.)"1 y'
> >     brila
> > ([: (+ +:)/ |.)"1
> >     n=:5 3$   0 0 0 0 0  1 0 1 0 0 1 1 1 0 0
> >     n
> > 0 0 0
> > 0 0 1
> > 0 1 0
> > 0 1 1
> > 1 0 0
> >     brila n
> > 0 1 2 3 4
> >
> > I'm still puzzled by how it works:
>    #. 1 0 1 0 1 0 1
> 85
>
>    13 :'x + 2*y'/ |. 1 0 1 0 1 0 1
> 85
>
> or
>
>    13 :'x + +: y'/ |. 1 0 1 0 1 0 1
> 85
>
>
> Simple J(?)
>
>    13 :'x + +: y'
> [ + [: +: ]
>
> or concise:
>
>   (++:)
>
> Base 10 example:
>
>    13 :'x + 10*y'/ |. 1 2 3 4 5
> 12345
>
>    (+10&*)/ |. 1 2 3 4 5
> 12345
>
>
> --
> Met vriendelijke groet,
> @@i = Arie Groeneveld
>
> ----------------------------------------------------------------------
> 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