[Jprogramming] J script files
Oleg Kobchenko
olegykj at yahoo.com
Mon Apr 16 12:31:13 HKT 2007
Scanning usually means lexical analysis, or lexing.
Although ". or 0&". can serve as scanners, together with ;: ,
they won't be useful for something like a date format:
;:'2001-01-01 00:00:00'
+----+-+--+-+--+---+---+--+
|2001|-|01|-|01|00:|00:|00|
+----+-+--+-+--+---+---+--+
Regular expressions can be used and a utility
adverb rxscan which accepts a verb applied to
each submatch and produces a dyad for pattern
and input, which can be used to make specific monads.
load'regex'
rxscan=: 1 : ',."1@(}."2)@rxmatches u;.0 ]'
datescan=: '(....)-(..)-(..) (..):(..):(..)' ".rxscan ]
datescan '2001-01-01 00:00:00'
2001 1 1 0 0 0
datescan '2001-01-01 00:00:00 2002-12-31 23:59:59'
2001 1 1 0 0 0
2002 12 31 23 59 59
--- ramacd <ramacd at nbnet.nb.ca> wrote:
> Amelia Stein wrote:
> > So how do you actually "scan" in a number from standard input? What
> > is the
> > syntax? Whether or not it is of good form in J, I have a presentation
> > to do
> > tomorrow where I need input from the keyboard.
>
> You don't actually scan in a number. You get a line of input as a
> string, or character list, to use the J term. Then you apply a string
> to number conversion on that string to get your numbers.
>
> a =: scan '' NB. Get a line of input from the keyboard
> b =: convert a NB. convert to numbers
> or, in a shorter form:
>
> b =: convert scan ''
>
> This works if you define 'convert' and 'scan', and also 'bind' which is
> part of the J distribution, and I suspect is described there.
>
> convert =: ".
> bind =: 2 : 'x@(y"_)'
> scan =: 1!:1 bind 1
>
> Hope this helps.
> >
> > On 4/15/07, Devon McCormick <devonmcc at gmail.com> wrote:
> >>
> >> Randy -
> >>
> >> I think it's a mis-characterization to say that J "isn't meant for user
> >> input".
> >> In fact, due to its interpretive nature, J handles user input
> >> beautifully
> >> compared
> >> to any conventional language, if you use the language itself. Of
> >> course,
> >> as
> >> an avid APLer, I'm sure this isn't news to you.
> >>
> >> But this prompt-based notion won't die, no matter how crippled it is
> >> compared
> >> to simply using native J. Take, for instance, the outline of the
> >> program
> >> that
> >> Amelia is writing: allow someone to enter some numbers, then return some
> >> descriptive statistics about them. Using J, I would naturally do
> >> something
> >> like
> >>
> >> (<./,>./,mean,stddev) 97.1 4.7 33 1.3 22 60 27.6 96.4 87.1 67.5
> >> 1.3 97.1 49.67 36.744585
> >>
> >> However, as Amelia's professor has constrained the problem, the
> >> "correct"
> >> session might look more like this:
> >>
> >> Enter some numbers: 97.1 4.7 33 1.3 22 60 27.6 96.4 87.1 67.5
> >> ** Error: can only accept 5 numbers.
> >> Enter some numbers: 97.1 4.7 33 1.3 22
> >> The minimum is 1.3.
> >> The maximum is 97.1.
> >> The mean is 31.62.
> >> The standard deviation is 38.813876.
> >>
> >> or some such limited, simplistic implementation. Notice how thoroughly
> >> inadequate this prompt-based paradigm is for getting any serious work
> >> done:
> >> it's probably constrained to some fixed number of entries or
> >> necessitates
> >> added complexity to acommodate a variable number of entries.
> >> Furthermore,
> >> an input mistake can only be corrected by re-typing the entire set of
> >> entries
> >> and the result can only be used by manually transferring it.
> >>
> >> (Of course, using a spreadsheet may also be a good way to handle a
> >> problem
> >> like this.)
> >>
> >> This prompt+manual input notion is a lousy paradigm that is
> >> encumbered by
> >> widely-accepted, unnecessary limitations of the past 50 years.
> >> Today, we
> >> have
> >> scalpels and laser beams but most people still insist on using sticks
> >> and
> >> rocks.
> >>
> >> However true all this all is, the problem of user input seems to be a
> >> recurring one in J.
> >> Those of us who use the language a lot have solved it for ourselves
> >> but it
> >> recurs
> >> regularly for beginners. We've talked about this a bit in the NYCJUG
> >> and
> >> the
> >> consensus seems to be 1) use file-based input, or 2) use a spreadsheet
> >> front-end.
> >>
> >> One other idea is to use the GUI-building capabilities of some other
> >> language,
> >> like Java or VB, and
> >> interface the resulting GUI with J. Until get something like
> >> this fully fleshed out on the Wiki, we may have to make do by referring
> >> people to
> >> the character-based solutions for Amelie that came out of this thread.
> >>
> >> Devon
> >>
> >> On 4/15/07, ramacd <ramacd at nbnet.nb.ca> wrote:
> >> >
> >> >
> >> >
> >> > Dan Bron wrote:
> >> > > This is easy to see if we take a reductionist approach: a single J
> >> > > token is either a built-in J primitive, or it's a user-defined name
> >> > > with an arbitrary definition. Primitives never change their
> >> definition
> >> > > (good thing!). And the dictionary of J explicitly states, at
> >> > > http://www.jsoftware.com/help/dictionary/dict2.htm that:
> >> > Primitives don't change their definition over a single version of J,
> >> > that is true. Over multiple versions it is a different story. In
> >> fact,
> >> > I long ago coined a term ("getting henked") for the suffering one
> >> > undergoes when one assumes upward compatibility.
> >> >
> >> > On the original idea of this thread, having a REPL facility, which
> >> > doesn't come in primitive-only J, doesn't strike me as a stretch of
> >> its
> >> > capabilities. I do wonder at the (if you want a responsive computer,
> >> > don't let a user near J) attitude, and where it comes from. Amelia's
> >> > note that J "isn't meant for user input." crystallizes a big
> >> misgiving I
> >> > have about J, even though I have been pro-J since J has been around.
> >> >
> >> > >: ...
> >> >
> >> > ----------------------------------------------------------------------
> >> > For information about J forums see http://www.jsoftware.com/forums.htm
> >> >
> >>
> >>
> >>
> >> --
> >> Devon McCormick, CFA
> >> ^me^ at acm.
> >> org is my
> >> preferred e-mail
> >> ----------------------------------------------------------------------
> >> 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
>
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
More information about the Programming
mailing list