You can also call c library functions.

   l=.({.~i.&LF)memr b,0,s[(c,' fgets *c *c i *')cd(<b=.mema 
s);(s=.256);<f=.{.(c,' fdopen * i *c')cd(d=.0 cd~' dup > i i',~c=.unxlib'c');1 
1$'r'
hello read line
   (;$)l
┌───────────────┬──┐
│hello read line│15│
└───────────────┴──┘
   (c,' fclose i *')cd<f


> On Jun 19, 2018, at 8:13 PM, Raul Miller <rauldmil...@gmail.com> wrote:
> 
> Actually, thinking about this - 1!:1 reads the whole file, so it's
> stty won't make a difference .- you'd need to use control-D to
> terminate everything you send to it interactively.
> 
> One approach - not incredibly efficient, but interactive
> line-at-a-time input isn't about efficiency, might be:
> 
>   LINE=: 2!:0'read line; echo "$line"'
> 
> This relies on 2!:0 being handled by /bin/sh (and note that you'll get
> a trailing LF character when you do this). The double quotes are so
> that redundant whitespace isn't removed by the shell...
> 
> Or, if you want that as a verb:
> 
> readline=: 2!:0 bind 'read line; echo "$line"'
> 
> I hope this helps.
> 
> -- 
> Raul
> On Tue, Jun 19, 2018 at 8:57 PM Raul Miller <rauldmil...@gmail.com> wrote:
>> 
>> Ah.. experimenting with this:
>> 
>> stdin'' reads till end of file (hit control-D to finish input)
>> readln'' as defined in this thread returns immediately, reading an empty 
>> string.
>> 
>> At least on *my* system.
>> 
>> I tried running
>> 
>> stty eol ^J before starting J, thinking that would fix it, but it did
>> not. But I'm running OSX where it might be that there's some "new and
>> improved" mechanism for defining the end of line character.
>> 
>> Anyways, this is likely an OS issue and the solution probably will
>> depend on your OS.
>> 
>> I hope this helps,
>> 
>> --
>> Raul
>> 
>> On Tue, Jun 19, 2018 at 8:41 PM Eric Iverson <eric.b.iver...@gmail.com> 
>> wrote:
>>> 
>>> I think the replies here miss an important part of the question. The #!
>>> script.
>>> 
>>> #! /usr/bin/j8
>>> stdin''
>>> 
>>> On Tue, Jun 19, 2018 at 8:21 PM, Don Guinn <dongu...@gmail.com> wrote:
>>> 
>>>> It appears that the right argument is ignored. Perhaps have it be displayed
>>>> on the same line as the input.
>>>> 
>>>> readln 'Name: '
>>>> 
>>>> On Tue, Jun 19, 2018 at 6:18 PM Raul Miller <rauldmil...@gmail.com> wrote:
>>>> 
>>>>>   1 -:&(3!:3) 01
>>>>> 1
>>>>> 
>>>>> No difference in what's represented, so the only difference is in how
>>>>> you type it / the leading zero / ...
>>>>> 
>>>>> Thanks,
>>>>> 
>>>>> --
>>>>> Raul
>>>>> 
>>>>> On Tue, Jun 19, 2018 at 8:15 PM Devon McCormick <devon...@gmail.com>
>>>>> wrote:
>>>>>> 
>>>>>> How does "01" differ from "1" in this context?
>>>>>> 
>>>>>> "readln" works for me within a session but I think James wants to do
>>>>>> something like pipe input into a J script.  This is not something I've
>>>>> done
>>>>>> but it would be interesting if we can do it.
>>>>>> 
>>>>>> On Tue, Jun 19, 2018 at 5:10 PM, Henry Rich <henryhr...@gmail.com>
>>>>> wrote:
>>>>>> 
>>>>>>> ?  The 01 is correct as it stands.  On Windows I get correct
>>>> operation:
>>>>>>> 
>>>>>>>   readln =: [: (1!:01) 1:
>>>>>>>   readln''
>>>>>>> abcdefg
>>>>>>> abcdefg
>>>>>>> 
>>>>>>> The first line is what I typed, the second is the JE's result
>>>>>>> 
>>>>>>> Henry Rich
>>>>>>> 
>>>>>>> 
>>>>>>> On 6/19/2018 5:05 PM, james faure wrote:
>>>>>>> 
>>>>>>>> Either way, it's no good
>>>>>>>> 
>>>>>>>> ________________________________
>>>>>>>> From: Programming <programming-boun...@forums.jsoftware.com> on
>>>>> behalf
>>>>>>>> of devonmcc <devon...@gmail.com>
>>>>>>>> Sent: Tuesday, June 19, 2018 11:00:39 PM
>>>>>>>> To: programm...@jsoftware.com
>>>>>>>> Subject: Re: [Jprogramming] getline
>>>>>>>> 
>>>>>>>> The "01" following the "!:" is probably supposed to be "0]1".
>>>>>>>> 
>>>>>>>> 
>>>>>>>> Sent from my Verizon, Samsung Galaxy smartphone
>>>>>>>> -------- Original message --------From: Michal Wallace <
>>>>>>>> michal.wall...@gmail.com> Date: 6/19/18  16:06  (GMT-05:00) To:
>>>>>>>> programm...@jsoftware.com Subject: Re: [Jprogramming] getline
>>>>>>>>  readln =: [: (1!:01) 1:
>>>>>>>> 
>>>>>>>> 
>>>>>>>> 
>>>>>>>> 
>>>>>>>> On Tue, Jun 19, 2018 at 2:45 PM james faure <james.fa...@epitech.eu
>>>>> 
>>>>>>>> wrote:
>>>>>>>> 
>>>>>>>> Hello, how can one read stdin one line at a time ?
>>>>>>>>> 
>>>>>>>>> 
>>>>>>>>> #! /usr/bin/j8
>>>>>>>>> 
>>>>>>>>> stdin''
>>>>>>>>> 
>>>>>>>>> 
>>>>>>>>> is no good.
>>>>>>>>> 
>>>>> ----------------------------------------------------------------------
>>>>>>>>> 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
>>>>>>>> 
>>>>>>> 
>>>>>>> 
>>>>>>> ---
>>>>>>> This email has been checked for viruses by AVG.
>>>>>>> https://www.avg.com
>>>>>>> 
>>>>>>> 
>>>>>>> ------------------------------------------------------------
>>>> ----------
>>>>>>> For information about J forums see http://www.jsoftware.com/
>>>> forums.htm
>>>>>>> 
>>>>>> 
>>>>>> 
>>>>>> 
>>>>>> --
>>>>>> 
>>>>>> Devon McCormick, CFA
>>>>>> 
>>>>>> Quantitative Consultant
>>>>>> ----------------------------------------------------------------------
>>>>>> 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