Hello world/Newline omission: Difference between revisions

Content deleted Content added
→‎{{header|bootBASIC}}: changed lang to "BASIC" in syntaxhighlight tag. Highlighting now works.
Querfeld (talk | contribs)
→‎J: update
Line 735: Line 735:


=={{header|J}}==
=={{header|J}}==
With ''jconsole'', <code>stdout</code> can be used.
On a linux system, you can use 1!:3 because stdout is a file:
<syntaxhighlight lang="j"> 'Goodbye, World!' 1!:3 <'/proc/self/fd/1'
<syntaxhighlight lang="j"> stdout
Goodbye, World! </syntaxhighlight>
1!:2&4</syntaxhighlight>
<code>1!:2&4</code> returns its input unmodified. To avoid implicit output (which would repeat the output), when used interactively:
However, J works in environments other than Linux, so...
<syntaxhighlight lang="j"> put=: 0 0 $ 1!:2&4

put 'Goodbye, World!'
Goodbye, World!</syntaxhighlight>
However, J also works in graphical environments, which might not be connected to standard output.
'''Solution''':<code>prompt</code> from the misc package.
'''Solution''':<code>prompt</code> from the misc package.
'''Example''':<syntaxhighlight lang="j"> load 'general/misc/prompt'
'''Example''':<syntaxhighlight lang="j"> load 'general/misc/prompt'
prompt 'Goodbye, World!'
prompt 'Goodbye, World!'
Goodbye, World!</syntaxhighlight>
Goodbye, World!</syntaxhighlight>
'''Notes''': J programs are normally run from a REPL, or session manager, which comes in several flavors. The traditional commandline-based terminal (jconsole), one of several desktop applications (jqt for the current version of J, jgtk and jwd for older but still supported versions), a web-based frontend (jhs), and various mobile apps (J for iOS, Android).
'''Notes''': J programs are normally run from a REPL, or session manager, which comes in several flavors. The traditional commandline-based terminal (jconsole), one of several desktop applications (jqt for the current version of J, jgtk and jwd for older versions), a web-based frontend (jhs), and various mobile apps (J for iOS, Android).


The specific session manager being used changes the context and therefore answer to this task. For example, when using J from a browser (including mobile browsers) newlines are omitted by default. Further, J provides strong tools for coalescing results and manipulating them prior to output, so newline elimination would typically happen before output rather than after.
The specific session manager being used changes the context and therefore answer to this task. For example, when using J from a browser (including mobile browsers) newlines are omitted by default. Further, J provides strong tools for coalescing results and manipulating them prior to output, so newline elimination would typically happen before output rather than after.


With that said, <code>prompt</code> handles the most common cases (using binary output for jconsole, so no newline is appended; adjusting the REPL prompt in the desktop apps to to elide the newline which is normally included by default, etc).
With that said, <code>prompt</code> handles the most common cases (using binary output for jconsole, so no newline is appended; adjusting the REPL prompt in the desktop apps to to elide the newline which is normally included by default, etc).


For truly automated processes, you'd almost always want this kind of functionality (omitting the newline when printing) in a file- or stream-oriented application. For those cases, the simple <code>text 1!:3 file</code> will append the text to the referenced file verbatim, without inserting any extra newlines.
For truly automated processes, you'd almost always want this kind of functionality (omitting the newline when printing) in a file- or stream-oriented application. For those cases, the simple <code>text 1!:3 file</code> will append the text to the referenced file verbatim, without inserting any extra newlines.


So, if a J programmer were asked to solve this task, the right approach would be to ask why that is needed, and then craft a solution appropriate to that situation.
So, if a J programmer were asked to solve this task, the right approach would be to ask why that is needed, and then craft a solution appropriate to that situation.