Re: [Jprogramming] Recursion crash WAS: depth vector APL translation
… I’d never had thought things like that would be that quickly found looks like it was quite tricky to get to the root cause kudos to Henry and whoever else looked into this Am 24.05.21 um 21:30 schrieb Henry Rich: > This crash happened when a recursive explicit function was calling > itself using a virtual argument, and the recursion gave an error. In > that case a memory block was not timely freed, and was freed later after > it had gone out of scope. I don't know why it didn't show up on jconsole. > > Good to have it fixed; thanks for the report. > > Henry Rich > > On 5/24/2021 10:24 AM, Raul Miller wrote: >> On OSX 10.14.6 (Mojave), I load the attached in j903 beta-j then run >> 0 dv ast >> >> and it crashes. >> >> Interestingly, if I include 0 dv ast in the script, that does not crash. >> >> I hope this helps, >> >> >> -- >> For information about J forums see http://www.jsoftware.com/forums.htm > > > -- -- mail written using NEO neo-layout.org -- For information about J forums see http://www.jsoftware.com/forums.htm
Re: [Jprogramming] Recursion crash WAS: depth vector APL translation
This crash happened when a recursive explicit function was calling itself using a virtual argument, and the recursion gave an error. In that case a memory block was not timely freed, and was freed later after it had gone out of scope. I don't know why it didn't show up on jconsole. Good to have it fixed; thanks for the report. Henry Rich On 5/24/2021 10:24 AM, Raul Miller wrote: On OSX 10.14.6 (Mojave), I load the attached in j903 beta-j then run 0 dv ast and it crashes. Interestingly, if I include 0 dv ast in the script, that does not crash. I hope this helps, -- 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
Re: [Jprogramming] Recursion crash WAS: depth vector APL translation
I can reproduce it! Great, thanks. Henry Rich On 5/24/2021 10:24 AM, Raul Miller wrote: On OSX 10.14.6 (Mojave), I load the attached in j903 beta-j then run 0 dv ast and it crashes. Interestingly, if I include 0 dv ast in the script, that does not crash. I hope this helps, -- 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
Re: [Jprogramming] Recursion crash WAS: depth vector APL translation
On OSX 10.14.6 (Mojave), I load the attached in j903 beta-j then run 0 dv ast and it crashes. Interestingly, if I include 0 dv ast in the script, that does not crash. I hope this helps, -- Raul Engine: j903/j64avx2/darwin Beta-j: commercial/2021-05-18T17:06:59 Library: 9.03.03 Qt IDE: 1.9.2/5.12.10(5.12.10) Platform: Darwin 64 Installer: J903 install InstallPath: /users/rauldmiller/applications/j903 Contact: www.jsoftware.com On Mon, May 24, 2021 at 10:18 AM Henry Rich wrote: > > I can't get this to crash under JQt. Can you provide detailed > instructions (I know you did once, I just want to make sure I'm doing > what you're doing)? > > And can others reproduce this crash? > > Henry Rich > > On 5/23/2021 10:37 PM, Raul Miller wrote: > > This does not crash for me under jconsole. > > > > This does crash for me under jqt. > > > > This also crashes for me under jhs. > > > > Here's the message I get in jconsole from jhs: > > > > /Users/rauldmiller/Applications/j903/bin/jhs.command: line 2: 36569 > > Segmentation fault: 11 "`dirname "$0"`/jconsole" > > ~addons/ide/jhs/core.ijs -js " init_jhs_'' " > > > > Here's the stack trace I get from jqt: > > > > Crashed Thread:0 Dispatch queue: com.apple.main-thread > > > > Exception Type:EXC_BAD_ACCESS (SIGSEGV) > > Exception Codes: KERN_INVALID_ADDRESS at 0x0024 > > Exception Note:EXC_CORPSE_NOTIFY > > > > Termination Signal:Segmentation fault: 11 > > Termination Reason:Namespace SIGNAL, Code 0xb > > Terminating Process: exc handler [36601] > > > > VM Regions Near 0x24: > > --> > > __TEXT 00010b381000-00010b386000 [ 20K] > > r-x/rwx SM=COW /Users/USER/* > > > > Thread 0 Crashed:: Dispatch queue: com.apple.main-thread > > 0 libj.dylib0x00011954a453 jtfa + 243 > > 1 libj.dylib0x00011954a2e1 freesymb + 545 > > 2 libj.dylib0x00011954aa60 jtmf + 208 > > 3 libj.dylib0x00011954ba48 jttpop + 216 > > 4 libj.dylib0x0001195428ca jdo + 362 > > 5 libj.dylib0x000119542680 JDo + 112 > > 6 libjqt.dylib 0x00010bf68df4 > > Jcon::cmdSentence(std::__1::basic_string > std::__1::char_traits, std::__1::allocator >) + 116 > > 7 libjqt.dylib 0x00010bf68c6a Jcon::cmdSentences() + > > 170 > > 8 libjqt.dylib 0x00010bf6a368 Tedit::docmd(QString) > > + 184 > > 9 libjqt.dylib 0x00010bf6b28a Tedit::enter() + 506 > > 10 org.qt-project.QtWidgets 0x0001140a530f > > QWidget::event(QEvent*) + 527 > > 11 org.qt-project.QtWidgets 0x00011414d11d QFrame::event(QEvent*) > > + 45 > > 12 org.qt-project.QtWidgets 0x00011422ddcf > > QTextEdit::event(QEvent*) + 415 > > 13 org.qt-project.QtWidgets 0x00011406982d > > QApplicationPrivate::notify_helper(QObject*, QEvent*) + 269 > > 14 org.qt-project.QtWidgets 0x00011406ad93 > > QApplication::notify(QObject*, QEvent*) + 947 > > 15 org.qt-project.QtCore 0x00010bac9d84 > > QCoreApplication::notifyInternal2(QObject*, QEvent*) + 212 > > 16 org.qt-project.QtWidgets 0x0001140c4151 0x114059000 + 438609 > > 17 org.qt-project.QtWidgets 0x0001140c3507 0x114059000 + 435463 > > 18 org.qt-project.QtWidgets 0x00011406982d > > QApplicationPrivate::notify_helper(QObject*, QEvent*) + 269 > > 19 org.qt-project.QtWidgets 0x00011406abd1 > > QApplication::notify(QObject*, QEvent*) + 497 > > 20 org.qt-project.QtCore 0x00010bac9d84 > > QCoreApplication::notifyInternal2(QObject*, QEvent*) + 212 > > 21 org.qt-project.QtGui 0x00010b3bcecf > > QGuiApplicationPrivate::processKeyEvent(QWindowSystemInterfacePrivate::KeyEvent*) > > + 191 > > 22 org.qt-project.QtGui 0x00010b3a2f8b > > QWindowSystemInterface::sendWindowSystemEvents(QFlags) > > + 219 > > 23 org.qt-project.QtGui 0x00010b39de75 > > QWindowSystemInterface::flushWindowSystemEvents(QFlags) > > + 581 > > 24 libqcocoa.dylib0x000116830368 0x116801000 + 193384 > > 25 libqcocoa.dylib0x000116830538 0x116801000 + 193848 > > 26 com.apple.AppKit 0x7fff3bb52367 > > -[NSWindow(NSEventRouting) _reallySendEvent:isDelayedEvent:] + 6840 > > 27 com.apple.AppKit 0x7fff3bb50667 > > -[NSWindow(NSEventRouting) sendEvent:] + 478 > > 28 libqcocoa.dylib0x000116833975 0x116801000 + 207221 > > 29 com.apple.AppKit 0x7fff3b9f0889 > > -[NSApplication(NSEvent) sendEvent:] + 2953 > > 30 libqcocoa.dylib0x00011683a9fa 0x116801000 + 236026 > > 31 com.apple.AppKit 0x7fff3b9de5c0 -[NSApplication run] + > > 755 > > 32 libqcocoa.dylib0x0001168370d3 0x116801000 + 221395 > > 33 org.qt-project.QtCore
Re: [Jprogramming] Recursion crash WAS: depth vector APL translation
I can't get this to crash under JQt. Can you provide detailed instructions (I know you did once, I just want to make sure I'm doing what you're doing)? And can others reproduce this crash? Henry Rich On 5/23/2021 10:37 PM, Raul Miller wrote: This does not crash for me under jconsole. This does crash for me under jqt. This also crashes for me under jhs. Here's the message I get in jconsole from jhs: /Users/rauldmiller/Applications/j903/bin/jhs.command: line 2: 36569 Segmentation fault: 11 "`dirname "$0"`/jconsole" ~addons/ide/jhs/core.ijs -js " init_jhs_'' " Here's the stack trace I get from jqt: Crashed Thread:0 Dispatch queue: com.apple.main-thread Exception Type:EXC_BAD_ACCESS (SIGSEGV) Exception Codes: KERN_INVALID_ADDRESS at 0x0024 Exception Note:EXC_CORPSE_NOTIFY Termination Signal:Segmentation fault: 11 Termination Reason:Namespace SIGNAL, Code 0xb Terminating Process: exc handler [36601] VM Regions Near 0x24: --> __TEXT 00010b381000-00010b386000 [ 20K] r-x/rwx SM=COW /Users/USER/* Thread 0 Crashed:: Dispatch queue: com.apple.main-thread 0 libj.dylib0x00011954a453 jtfa + 243 1 libj.dylib0x00011954a2e1 freesymb + 545 2 libj.dylib0x00011954aa60 jtmf + 208 3 libj.dylib0x00011954ba48 jttpop + 216 4 libj.dylib0x0001195428ca jdo + 362 5 libj.dylib0x000119542680 JDo + 112 6 libjqt.dylib 0x00010bf68df4 Jcon::cmdSentence(std::__1::basic_string, std::__1::allocator >) + 116 7 libjqt.dylib 0x00010bf68c6a Jcon::cmdSentences() + 170 8 libjqt.dylib 0x00010bf6a368 Tedit::docmd(QString) + 184 9 libjqt.dylib 0x00010bf6b28a Tedit::enter() + 506 10 org.qt-project.QtWidgets 0x0001140a530f QWidget::event(QEvent*) + 527 11 org.qt-project.QtWidgets 0x00011414d11d QFrame::event(QEvent*) + 45 12 org.qt-project.QtWidgets 0x00011422ddcf QTextEdit::event(QEvent*) + 415 13 org.qt-project.QtWidgets 0x00011406982d QApplicationPrivate::notify_helper(QObject*, QEvent*) + 269 14 org.qt-project.QtWidgets 0x00011406ad93 QApplication::notify(QObject*, QEvent*) + 947 15 org.qt-project.QtCore 0x00010bac9d84 QCoreApplication::notifyInternal2(QObject*, QEvent*) + 212 16 org.qt-project.QtWidgets 0x0001140c4151 0x114059000 + 438609 17 org.qt-project.QtWidgets 0x0001140c3507 0x114059000 + 435463 18 org.qt-project.QtWidgets 0x00011406982d QApplicationPrivate::notify_helper(QObject*, QEvent*) + 269 19 org.qt-project.QtWidgets 0x00011406abd1 QApplication::notify(QObject*, QEvent*) + 497 20 org.qt-project.QtCore 0x00010bac9d84 QCoreApplication::notifyInternal2(QObject*, QEvent*) + 212 21 org.qt-project.QtGui 0x00010b3bcecf QGuiApplicationPrivate::processKeyEvent(QWindowSystemInterfacePrivate::KeyEvent*) + 191 22 org.qt-project.QtGui 0x00010b3a2f8b QWindowSystemInterface::sendWindowSystemEvents(QFlags) + 219 23 org.qt-project.QtGui 0x00010b39de75 QWindowSystemInterface::flushWindowSystemEvents(QFlags) + 581 24 libqcocoa.dylib0x000116830368 0x116801000 + 193384 25 libqcocoa.dylib0x000116830538 0x116801000 + 193848 26 com.apple.AppKit 0x7fff3bb52367 -[NSWindow(NSEventRouting) _reallySendEvent:isDelayedEvent:] + 6840 27 com.apple.AppKit 0x7fff3bb50667 -[NSWindow(NSEventRouting) sendEvent:] + 478 28 libqcocoa.dylib0x000116833975 0x116801000 + 207221 29 com.apple.AppKit 0x7fff3b9f0889 -[NSApplication(NSEvent) sendEvent:] + 2953 30 libqcocoa.dylib0x00011683a9fa 0x116801000 + 236026 31 com.apple.AppKit 0x7fff3b9de5c0 -[NSApplication run] + 755 32 libqcocoa.dylib0x0001168370d3 0x116801000 + 221395 33 org.qt-project.QtCore 0x00010bac539f QEventLoop::exec(QFlags) + 431 34 libjqt.dylib 0x00010bf5d040 state_run + 176 35 jqt0x00010b38552e main + 1022 I hope this helps, -- 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
Re: [Jprogramming] Recursion crash WAS: depth vector APL translation
This is most unexpected. Your sentence has finished execution, and you are freeing a symbol table, either from a locale or from an explicit definition. It encounters an invalid address. Our Jqt and JHS divisions will need to look into this. The other front-ends have to estimate the beginning of the stack, and it appears that they are missing it. Henry Rich On 5/23/2021 10:37 PM, Raul Miller wrote: This does not crash for me under jconsole. This does crash for me under jqt. This also crashes for me under jhs. Here's the message I get in jconsole from jhs: /Users/rauldmiller/Applications/j903/bin/jhs.command: line 2: 36569 Segmentation fault: 11 "`dirname "$0"`/jconsole" ~addons/ide/jhs/core.ijs -js " init_jhs_'' " Here's the stack trace I get from jqt: Crashed Thread:0 Dispatch queue: com.apple.main-thread Exception Type:EXC_BAD_ACCESS (SIGSEGV) Exception Codes: KERN_INVALID_ADDRESS at 0x0024 Exception Note:EXC_CORPSE_NOTIFY Termination Signal:Segmentation fault: 11 Termination Reason:Namespace SIGNAL, Code 0xb Terminating Process: exc handler [36601] VM Regions Near 0x24: --> __TEXT 00010b381000-00010b386000 [ 20K] r-x/rwx SM=COW /Users/USER/* Thread 0 Crashed:: Dispatch queue: com.apple.main-thread 0 libj.dylib0x00011954a453 jtfa + 243 1 libj.dylib0x00011954a2e1 freesymb + 545 2 libj.dylib0x00011954aa60 jtmf + 208 3 libj.dylib0x00011954ba48 jttpop + 216 4 libj.dylib0x0001195428ca jdo + 362 5 libj.dylib0x000119542680 JDo + 112 6 libjqt.dylib 0x00010bf68df4 Jcon::cmdSentence(std::__1::basic_string, std::__1::allocator >) + 116 7 libjqt.dylib 0x00010bf68c6a Jcon::cmdSentences() + 170 8 libjqt.dylib 0x00010bf6a368 Tedit::docmd(QString) + 184 9 libjqt.dylib 0x00010bf6b28a Tedit::enter() + 506 10 org.qt-project.QtWidgets 0x0001140a530f QWidget::event(QEvent*) + 527 11 org.qt-project.QtWidgets 0x00011414d11d QFrame::event(QEvent*) + 45 12 org.qt-project.QtWidgets 0x00011422ddcf QTextEdit::event(QEvent*) + 415 13 org.qt-project.QtWidgets 0x00011406982d QApplicationPrivate::notify_helper(QObject*, QEvent*) + 269 14 org.qt-project.QtWidgets 0x00011406ad93 QApplication::notify(QObject*, QEvent*) + 947 15 org.qt-project.QtCore 0x00010bac9d84 QCoreApplication::notifyInternal2(QObject*, QEvent*) + 212 16 org.qt-project.QtWidgets 0x0001140c4151 0x114059000 + 438609 17 org.qt-project.QtWidgets 0x0001140c3507 0x114059000 + 435463 18 org.qt-project.QtWidgets 0x00011406982d QApplicationPrivate::notify_helper(QObject*, QEvent*) + 269 19 org.qt-project.QtWidgets 0x00011406abd1 QApplication::notify(QObject*, QEvent*) + 497 20 org.qt-project.QtCore 0x00010bac9d84 QCoreApplication::notifyInternal2(QObject*, QEvent*) + 212 21 org.qt-project.QtGui 0x00010b3bcecf QGuiApplicationPrivate::processKeyEvent(QWindowSystemInterfacePrivate::KeyEvent*) + 191 22 org.qt-project.QtGui 0x00010b3a2f8b QWindowSystemInterface::sendWindowSystemEvents(QFlags) + 219 23 org.qt-project.QtGui 0x00010b39de75 QWindowSystemInterface::flushWindowSystemEvents(QFlags) + 581 24 libqcocoa.dylib0x000116830368 0x116801000 + 193384 25 libqcocoa.dylib0x000116830538 0x116801000 + 193848 26 com.apple.AppKit 0x7fff3bb52367 -[NSWindow(NSEventRouting) _reallySendEvent:isDelayedEvent:] + 6840 27 com.apple.AppKit 0x7fff3bb50667 -[NSWindow(NSEventRouting) sendEvent:] + 478 28 libqcocoa.dylib0x000116833975 0x116801000 + 207221 29 com.apple.AppKit 0x7fff3b9f0889 -[NSApplication(NSEvent) sendEvent:] + 2953 30 libqcocoa.dylib0x00011683a9fa 0x116801000 + 236026 31 com.apple.AppKit 0x7fff3b9de5c0 -[NSApplication run] + 755 32 libqcocoa.dylib0x0001168370d3 0x116801000 + 221395 33 org.qt-project.QtCore 0x00010bac539f QEventLoop::exec(QFlags) + 431 34 libjqt.dylib 0x00010bf5d040 state_run + 176 35 jqt0x00010b38552e main + 1022 I hope this helps, -- 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
Re: [Jprogramming] Recursion crash WAS: depth vector APL translation
This does not crash for me under jconsole. This does crash for me under jqt. This also crashes for me under jhs. Here's the message I get in jconsole from jhs: /Users/rauldmiller/Applications/j903/bin/jhs.command: line 2: 36569 Segmentation fault: 11 "`dirname "$0"`/jconsole" ~addons/ide/jhs/core.ijs -js " init_jhs_'' " Here's the stack trace I get from jqt: Crashed Thread:0 Dispatch queue: com.apple.main-thread Exception Type:EXC_BAD_ACCESS (SIGSEGV) Exception Codes: KERN_INVALID_ADDRESS at 0x0024 Exception Note:EXC_CORPSE_NOTIFY Termination Signal:Segmentation fault: 11 Termination Reason:Namespace SIGNAL, Code 0xb Terminating Process: exc handler [36601] VM Regions Near 0x24: --> __TEXT 00010b381000-00010b386000 [ 20K] r-x/rwx SM=COW /Users/USER/* Thread 0 Crashed:: Dispatch queue: com.apple.main-thread 0 libj.dylib0x00011954a453 jtfa + 243 1 libj.dylib0x00011954a2e1 freesymb + 545 2 libj.dylib0x00011954aa60 jtmf + 208 3 libj.dylib0x00011954ba48 jttpop + 216 4 libj.dylib0x0001195428ca jdo + 362 5 libj.dylib0x000119542680 JDo + 112 6 libjqt.dylib 0x00010bf68df4 Jcon::cmdSentence(std::__1::basic_string, std::__1::allocator >) + 116 7 libjqt.dylib 0x00010bf68c6a Jcon::cmdSentences() + 170 8 libjqt.dylib 0x00010bf6a368 Tedit::docmd(QString) + 184 9 libjqt.dylib 0x00010bf6b28a Tedit::enter() + 506 10 org.qt-project.QtWidgets 0x0001140a530f QWidget::event(QEvent*) + 527 11 org.qt-project.QtWidgets 0x00011414d11d QFrame::event(QEvent*) + 45 12 org.qt-project.QtWidgets 0x00011422ddcf QTextEdit::event(QEvent*) + 415 13 org.qt-project.QtWidgets 0x00011406982d QApplicationPrivate::notify_helper(QObject*, QEvent*) + 269 14 org.qt-project.QtWidgets 0x00011406ad93 QApplication::notify(QObject*, QEvent*) + 947 15 org.qt-project.QtCore 0x00010bac9d84 QCoreApplication::notifyInternal2(QObject*, QEvent*) + 212 16 org.qt-project.QtWidgets 0x0001140c4151 0x114059000 + 438609 17 org.qt-project.QtWidgets 0x0001140c3507 0x114059000 + 435463 18 org.qt-project.QtWidgets 0x00011406982d QApplicationPrivate::notify_helper(QObject*, QEvent*) + 269 19 org.qt-project.QtWidgets 0x00011406abd1 QApplication::notify(QObject*, QEvent*) + 497 20 org.qt-project.QtCore 0x00010bac9d84 QCoreApplication::notifyInternal2(QObject*, QEvent*) + 212 21 org.qt-project.QtGui 0x00010b3bcecf QGuiApplicationPrivate::processKeyEvent(QWindowSystemInterfacePrivate::KeyEvent*) + 191 22 org.qt-project.QtGui 0x00010b3a2f8b QWindowSystemInterface::sendWindowSystemEvents(QFlags) + 219 23 org.qt-project.QtGui 0x00010b39de75 QWindowSystemInterface::flushWindowSystemEvents(QFlags) + 581 24 libqcocoa.dylib0x000116830368 0x116801000 + 193384 25 libqcocoa.dylib0x000116830538 0x116801000 + 193848 26 com.apple.AppKit 0x7fff3bb52367 -[NSWindow(NSEventRouting) _reallySendEvent:isDelayedEvent:] + 6840 27 com.apple.AppKit 0x7fff3bb50667 -[NSWindow(NSEventRouting) sendEvent:] + 478 28 libqcocoa.dylib0x000116833975 0x116801000 + 207221 29 com.apple.AppKit 0x7fff3b9f0889 -[NSApplication(NSEvent) sendEvent:] + 2953 30 libqcocoa.dylib0x00011683a9fa 0x116801000 + 236026 31 com.apple.AppKit 0x7fff3b9de5c0 -[NSApplication run] + 755 32 libqcocoa.dylib0x0001168370d3 0x116801000 + 221395 33 org.qt-project.QtCore 0x00010bac539f QEventLoop::exec(QFlags) + 431 34 libjqt.dylib 0x00010bf5d040 state_run + 176 35 jqt0x00010b38552e main + 1022 I hope this helps, -- Raul On Sun, May 23, 2021 at 9:04 PM Henry Rich wrote: > > I entered this into a new session: > > N=:0 > > dv =: {{ > if. 20 < N=: N+1 do. throw. end. > echo y > ([echo) (];(>:x) dv [)/\ |.x;}.y > }} > > t=:'.' > ast=:t;(t;t);(t;(t;t);t);(t;(t;t;t);(t;t;t);t) > > 0 dv ast > > I got the result > > +-+-+---+-+---+---+-+ > |.|+-+-+|+-+-+-+|.|+-+-+-+|+-+-+-+|.| > | ||.|.|||.|+-+-+|.|| ||.|.|.|||.|.|.|| | > | |+-+-+|| ||.|.|| || |+-+-+-+|+-+-+-+| | > | | || |+-+-+| || | | | | > | | |+-+-+-+| | | | | > +-+-+---+-+---+---+-+ > +-+ > |.| > +-+ > ++ > || > ++ > ...about 18 repetitions... > ++ > || > ++ > |uncaught throw.: dv > | ([echo)(];(>:x)dv[)/\|.x;}.y > > > I then ran > > t=:'.' > ast=:t;(t;t);(t;(t;t);t);(t;(t;t;t);(t;t;t);t) > dv =: {{ > if. 0=#y do. x return. end. > (];(>:x)
Re: [Jprogramming] Recursion
Normal J style is control on the left, data on the right, so I have redefined your spec to take the number of doublings as x and the number to be doubled as y. d =: ($: (, +:@{:))^:(> #) 10 d 7 7 14 28 56 112 224 448 896 1792 3584 Dissect can be helpful in tracing through recursive execution. In a sentence like this ^: should be read as 'if'. Henry Rich On 6/12/2018 2:07 AM, Skip Cave wrote: I want to try to understand recursive functions in J. To start this learning process, I want to investigate J verbs that will generate a doubling sequence. For example, the verb 'd' where x = the starting integer, and y = the number of iterations: 2 d 6 2 4 8 16 32 64 5 d 4 5 10 20 40 7 d 10 7 14 28 56 112 224 448 896 1792 3584 Define three different simple recursive verbs in J, to implement this recursive doubling function: 1. d1 - Just calling the function recursively 2. d2 - Using the Power operator ^: 3. d3 - Using Spread S: and Memo M. Skip Skip Cave Cave Consulting LLC -- For information about J forums see http://www.jsoftware.com/forums.htm --- This email has been checked for viruses by AVG. http://www.avg.com -- For information about J forums see http://www.jsoftware.com/forums.htm
Re: [Jprogramming] Recursion
S: isn't relevant to recusion, though $: is for tacit versions. if you want to double a fixed number of times, then ^: is iteration and appropriate. To help in using $:, nearly every problem can be formulated with @. if monad final_display ` $:@:intermediate_transform @.stop_condition if dyad final_display `(transformofleft@[ $: intermediate_transform@] )@.stop_condition imt =: ] , +:@{: if the problem was double y arg until it is greater than x arg 100 }:@]`([ $: imt@])@.([ >: {:@]) 2 2 4 8 16 32 64 if as originally tasked, a fixed amount of times (but transform both sides) 6 ]`(<:@[ $: imt@])@.(1 < [) 5 5 10 20 40 80 160 From: Skip Cave To: "programm...@jsoftware.com" Sent: Tuesday, June 12, 2018 2:08 AM Subject: [Jprogramming] Recursion I want to try to understand recursive functions in J. To start this learning process, I want to investigate J verbs that will generate a doubling sequence. For example, the verb 'd' where x = the starting integer, and y = the number of iterations: 2 d 6 2 4 8 16 32 64 5 d 4 5 10 20 40 7 d 10 7 14 28 56 112 224 448 896 1792 3584 Define three different simple recursive verbs in J, to implement this recursive doubling function: 1. d1 - Just calling the function recursively 2. d2 - Using the Power operator ^: 3. d3 - Using Spread S: and Memo M. Skip Skip Cave Cave Consulting LLC -- For information about J forums see http://www.jsoftware.com/forums.htm -- For information about J forums see http://www.jsoftware.com/forums.htm
Re: [Jprogramming] Recursion
There's a slight conflict between your description (right argument is number of recursive iterations) and your example results (which show one less doubling than is indicated in your right argument). I am also not sure how using S: would be useful, so I left out d3. There are actually several possibilities for d1, though. Anyways, this might be close to what you are looking for: d1=:4 :0 if. 0:@[)~ Thanks, -- Raul On Tue, Jun 12, 2018 at 2:08 AM Skip Cave wrote: > > I want to try to understand recursive functions in J. To start this > learning process, I want to investigate J verbs that will generate a > doubling sequence. For example, the verb 'd' where x = the starting > integer, and y = the number of iterations: > >2 d 6 > 2 4 8 16 32 64 > >5 d 4 > 5 10 20 40 > >7 d 10 > 7 14 28 56 112 224 448 896 1792 3584 > > Define three different simple recursive verbs in J, to implement this > recursive doubling function: > 1. d1 - Just calling the function recursively > 2. d2 - Using the Power operator ^: > 3. d3 - Using Spread S: and Memo M. > > Skip > > Skip Cave > Cave Consulting LLC > -- > For information about J forums see http://www.jsoftware.com/forums.htm -- For information about J forums see http://www.jsoftware.com/forums.htm
Re: [Jprogramming] Recursion
As far as I know these definition conjunction (:) forms were never implemented in any public version of the interpreter (however, abut (`:0), generalized insert (`:3), or simply (/), and train (`:6) do work). It would be an interesting and useful exercise to write most, if not all those adverbs (particularly in a fixed tacit fashion), together with a conjunction, or an adverb, that collects them. For example, the adverb dynamic compose (:57) can be written wickedly as follows, NB. Dynamic Compose (:57)... o=. @: ( Cloak=. (<(<,'4'),<(<(<,'4'),<;:'0:`'),<(<,'4'),<;:',^:') (0:`)(,^:) ) ,^:(0:`((0:`)(,^:))) amper=. Cloak <'&' train=. (evoke=. Cloak <'`:')&6 Compose=. (amper~&:train)/ o |. Compose v0`v1`v2`v3 v0&v1&v2&v3 This wicked verb, as any other verb, can in turn be masked as an adverb, C=. <(<,'4'),<(<,'"'),<(,'0');_[ O=. <'@:' DN=. <(<,'4'),<(<,'`'),<(<,'0'),<<(,'0');_ [ VG=. <(<,'4'),<(<'`:'),<(,'0');6 ( Adv=. (`(C,O,DN,VG)) (@.(1;0 2;3;4)) ) (`("_`@:`(`_)`(`:6)))(@.(1;0 2;3;4)) u Adv ((("_)(u@:))(`_))(`:6) 1 2 3 % Adv 1 0.5 0.33 ( DynamicCompose=. Compose f.Adv ) ((("_)(,^:(0:`&)~&:(,^:(0:``:)&6)/@:|.@:))(`_))(`:6) v0`v1`v2`v3 DynamicCompose v0&v1&v2&v3 Personally though, I prefer dynamic appose, NB. Dynamic Appose... appose=. Cloak <'&:' Appose=. (appose~&:train)/ o |. v0`v1`v2`v3 (DynamicAppose=. Appose f.Adv) v0&:v1&:v2&:v3 On Sat, Nov 23, 2013 at 5:12 PM, Y-01 wrote: > Hi@all > > I just read an article Gerunds and Representations [Robert Bernecky and > Roger Hui, 17 july 2007] (www.snakeisland.com/gerunds.ps) and stopped on > searching bijection on J7 (or J6 or J8). > > Ok, lets go to the most interesting place ... page 6 > > Fibonacci numbers > > cb =. ] , +/ @( _2&{. )@] > fib =. >&1 ` (i.@>:) ` cb ` <: `:4 > fib 7 > > 0 1 1 2 3 5 8 13 > > 1. How can we write this in J7 (without $:-solution).? > NB. without > NB. fib =: 1:`1:`( (+/@:(_2&{.))@:($:"0 (<:@<: , <:) ) )@. (2&<.) "0 > NB. fib i.10 > NB. 1 1 2 3 5 8 13 21 34 55 > > http://www.jsoftware.com/help/dictionary/d612.htm say that there are only: > > m `: 0 *Append* > m `: 3 *Insert* > m `: 6 *Train* > > > 2. Does J looses `: 4 (recursive compute in such view) `:5 (case) `:1 > (until) in it's evolution? > (replacement with @.) > > 3. Maybe there is an article or page about J-gerunds-evolution and it's > nearest future? > > thnks > -- > For information about J forums see http://www.jsoftware.com/forums.htm > -- For information about J forums see http://www.jsoftware.com/forums.htm
Re: [Jprogramming] Recursion
Why avoid $:? I do not know the definition of `:4 and am in too much of a hurry to find it right now, but you can always use the name of the verb if you want to do recursion. But this looks like a close approximation to that algorithm: (] , +/ @( _2&{. )@])^:(<:@[)&1 1 Or, if you want anonymous recursion you could use a y combinator implementation (but this is going to be slow, in J, because reinventing existing facilities is a sign that your efforts might best be spent elsewhere). There are a couple y combinator implementations at: http://rosettacode.org/wiki/Y_combinator Thanks, -- Raul On Sat, Nov 23, 2013 at 5:12 PM, Y-01 wrote: > Hi@all > > I just read an article Gerunds and Representations [Robert Bernecky and > Roger Hui, 17 july 2007] (www.snakeisland.com/gerunds.ps) and stopped on > searching bijection on J7 (or J6 or J8). > > Ok, lets go to the most interesting place ... page 6 > > Fibonacci numbers > > cb =. ] , +/ @( _2&{. )@] > fib =. >&1 ` (i.@>:) ` cb ` <: `:4 > fib 7 > > 0 1 1 2 3 5 8 13 > > 1. How can we write this in J7 (without $:-solution).? > NB. without > NB. fib =: 1:`1:`( (+/@:(_2&{.))@:($:"0 (<:@<: , <:) ) )@. (2&<.) "0 > NB. fib i.10 > NB. 1 1 2 3 5 8 13 21 34 55 > > http://www.jsoftware.com/help/dictionary/d612.htm say that there are only: > > m `: 0 *Append* > m `: 3 *Insert* > m `: 6 *Train* > > > 2. Does J looses `: 4 (recursive compute in such view) `:5 (case) `:1 > (until) in it's evolution? > (replacement with @.) > > 3. Maybe there is an article or page about J-gerunds-evolution and it's > nearest future? > > thnks > -- > For information about J forums see http://www.jsoftware.com/forums.htm -- For information about J forums see http://www.jsoftware.com/forums.htm