s=: 'Hello world'
write=: {{p [ y memw p,0,(>: # y),2 [ p=. mema >: # y}}
read=: {{res [ memf y [ res=. memr y,0,_1,2}}
(read@write&.> <\ s) -: <\ s
0
Inspecting the result with
(read@write&.> <\ s) (;<)&,. <\ s
We can see a conflict with a statement made at
https://code.jsoftware.com/wiki/Guides/DLLs/Memory_Management (and
other places):
"If type is char, count can be 1 greater than the length of the string
left argument, in which case a 0 is appended (writing a C string)."
------------------
I think the cause here is that the memw code was not updated to cope
with virtual blocks. Prior to j901, that trailing 0 would have been
added to the character list when it was written to memory.
I hope this helps,
--
Raul
On Sun, Feb 27, 2022 at 9:49 AM Henry Rich <[email protected]> wrote:
>
> I haven't been following this thread. I just looked at the NuVoc for
> read/write & they look right to me. What needs changing?
>
> Henry Rich
>
> On 2/27/2022 7:03 AM, bill lam wrote:
> > Looks like either need to fix J engine or the documentation.
> >
> > On Sat, 26 Feb 2022 at 4:13 AM Raul Miller <[email protected]> wrote:
> >
> >> I am trying to understand what you mean here.
> >>
> >> Your 'read' verb does not read from memory. Instead, it writes a zero
> >> to an offset in some freshly allocated memory and returns the address
> >> of that allocation.
> >>
> >> Similarly, your 'write' verb does not write to memory. Instead, it
> >> reads characters from the previously allocated memory, up to the point
> >> where it finds a zero (and fortunately, you had ensured that there
> >> would be one when you invoked 'read').
> >>
> >> Anyways, basically it looks like you've built a small system to read
> >> some arbitrary bytes from memory and then are using them in some
> >> larger algorithm.
> >>
> >> But I am not sure why you would expect an operation which reads
> >> arbitrary memory to be deterministic.
> >>
> >> Have I overlooked something important?
> >>
> >> Thanks,
> >>
> >> --
> >> Raul
> >>
> >> On Fri, Feb 25, 2022 at 3:01 PM John Ference <[email protected]>
> >> wrote:
> >>> Hello,
> >>> Is this construction consistent with the design specs of the memory
> >>> management functions?
> >>>
> >>> s =. 'Hello world'
> >>>
> >>> read =. {{p [ y memw p,0,(>: # y),2 [ p =. mema >: # y}}
> >>>
> >>> write =. {{res [ memf y [ res =. memr y,0,_1,2}}
> >>>
> >>>
> >>> NB. test:
> >>>
> >>> <./ (,. write@read&.> <\ s) = (,. <\ s)
> >>>
> >>> Results are non-deterministic, but the results at the test at the end
> >>> typically return 0.
> >>>
> >>> Visual inspection of the result suggests the capability to auto-append
> >> and
> >>> then auto-find an end-of-string indicator may not be working.
> >>>
> >>> specs: https://code.jsoftware.com/wiki/Guides/DLLs/Memory_Management
> >>>
> >>> Regards,
> >>> John
> >>> ----------------------------------------------------------------------
> >>> 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
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm