The simpliest Hello World in Newspeak Wasm?

64 views
Skip to first unread message

Milan Zimmermann

unread,
Jul 13, 2021, 5:00:06 PM7/13/21
to Newspeak Programming Language
To show concepts and concerns in simple examples, one wants the least mandatory code to shadow the code for the concepts. 

In that regard, I appreciate the one-liner brevity of the Newspeak on Squeak Hello World.

class HelloBraveNewWorld usingPlatform: platform = (
  platform squeak Transcript open show: ‘Hello, Oh Brave new world’.
)

Well, looks like between Squek and Wasm  versions the packaging  parameters changed from platform to manifest, so  in Wasm it would be like (obviously not usable)

class HelloBraveNewWorld packageUsing: manifest = () 
(
  public main: platform args: args = (
  platform squeak Transcript open show: ‘Hello, Oh Brave new world’.
  )
)

In the browser version, the only one-liner Hello World I can come up with 

class HelloWorld packageUsing: manifest = (
) (
  public main: platform args: args = (
    ((platform js global at: 'document') at: 'body' put: ((platform js global at: 'document') createElement: 'body')) appendChild: ((platform js global at: 'document') createTextNode: 'Hello, World!').
  )

Even through it is an absolutely ugly and unreadable one-liner, I like it does not consume any slots, does not use variables, methods, etc, so if a slot, variable or method is added to the example, is clearly related to the concept we want to explain. Yet. It is ugly, *and* it destroys the back button, I suppose due to the body being trashed.

Would there be a better known and nicer one-liner Hello World in Newspeak Wasm?

It's no big deal, but just in case,

Thanks
Milan


Gilad Bracha

unread,
Jul 13, 2021, 6:48:15 PM7/13/21
to newspeak...@googlegroups.com
Well, it all depends what you mean by Hello World. In the C tradition, the goal of creating some minimal code that does something useful is conflated with creating a complete program and packaging it, because there is no other option. In the civilized world,  there is a spectrum,

(1) The simplest thing (what I would put in a tutorial) is to type

'Hello World'

in a workspace and evaluate it. Here Hello World is a is an expression. This is in keeping with the role of Hello world as an introduction to creating code.

There is also the method 'out, whose future disposition is in doubt, as in

'Hello World' out

which prints to the JS console. Here Hello World is still an expression, but feels more like an imperative statement causing something to happen.

There are questions around #out that are orthogonal to the options I present here:

a. #out provides global capability. How harmful is it if we allow universal access to it? In Unix terms, is the output stream a universal capability?  We do allow the error stream as a universal capability (almost) since we allow  any program to raise an exception via the Error method of Object.  A thorough security review might lead us to prohibit that too.
b.  There should be a Newspeak object like Transcript in the Smalltalk system, which you can use as that capability. Should that object be part of Platform? The IDE? Should the IDE provide an augmented platform where Object  supports such a convenience, (or others, like #break?). I feel that in the development setting, #out or access to Transcript via Object is essential. But that may not carry through to the production environment.

If we don't have #out, we can certainly  use Transcript in the IDE, as in

Transcript show: 'Hello World'


(2) class HelloWorld = ( 'Hello World' out. )().  This is more like defining Hello World as a program or library. If we want this to work outside the IDE and decide that access to #out is forbidden, we get

class HelloWorld onConsole: Transcript  = (
  Transcript show: 'Hello World'.
)()

(3)
class
HelloApp packageUsing: manifest = () (
public main: platform args: args = (
    'Hello World' out.
))

or

class HelloApp packageUsing: manifest = (
  | Transcript = manifest Transcript. |
)

public main: platform args: args = (
     Transcript show: 'Hello World'.
))


Now we have Hello World as a full application.

(4) Lastly we have something like your proposal, in which  Hello World is a DOM application - involving things like FFI to JS and GUI. While this is an option, I try and pave over JS whenever possible.

--
You received this message because you are subscribed to the Google Groups "Newspeak Programming Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to newspeaklangua...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/newspeaklanguage/f0ce65f5-cc02-4f29-abf6-06a46dd13380n%40googlegroups.com.


--
Cheers, Gilad

Milan Zimmermann

unread,
Jul 13, 2021, 8:32:48 PM7/13/21
to Newspeak Programming Language
Gilad,

Your response, again, cleared so much of my confusion. I am happy I asked about the Hello World. 

Initially, I did not want to ask, knowing it is like day 10 and I still did not pass over the Hello World :)

So the items here describe what your response cleared for me,  and some notes.

- That we can use Transcript. I made clearly a baseless assumption, that Transcript does not exist in the Wasm version, and did not look. 
- That I can use 'Hello world' out (understand it may not exist in the future)
- I created the DOM one-liner grudgingly, thinking DOM manipulation is the only way to output anything in this version (if one wants an app, not just Workspace use).
- Your "ladder" of going through Hello World from the Workspace, to a library, to an App, is the exercise I meant to go through and document! That's whjy my quest for a better one-liner Hello World.   I wanted to start with a Hello World App (did not say that) and wanted to create examples one of each : Class -> Libary -> App, and discuss how each is packaged and distributed (well, not class) - in other words, I plan to discuss and document which "convention named method(s)" needs to be added as we go up that ladder. And using your examples is much nicer then the DOM version.
- Now when I have your examples, may I use them?  

But I do have a question or two inline, if you do not mind ...


On Tuesday, 13 July 2021 at 15:48:15 UTC-7 Gilad Bracha wrote:
Well, it all depends what you mean by Hello World.

True, I really meant an App - sort of a better version of my DOM version 

In the C tradition, the goal of creating some minimal code that does something useful is conflated with creating a complete program and packaging it, because there is no other option. In the civilized world,  there is a spectrum,\
 

(1) The simplest thing (what I would put in a tutorial) is to type

'Hello World'

in a workspace and evaluate it. Here Hello World is a is an expression. This is in keeping with the role of Hello world as an introduction to creating code.

There is also the method 'out, whose future disposition is in doubt, as in

'Hello World' out

which prints to the JS console.

I see the difference now. between 'Hello World' and 'Hello World' out in Workspace.
 
Here Hello World is still an expression, but feels more like an imperative statement causing something to happen.

There are questions around #out that are orthogonal to the options I present here:

a. #out provides global capability. How harmful is it if we allow universal access to it? In Unix terms, is the output stream a universal capability?  We do allow the error stream as a universal capability (almost) since we allow  any program to raise an exception via the Error method of Object.  A thorough security review might lead us to prohibit that too.
b.  There should be a Newspeak object like Transcript in the Smalltalk system, which you can use as that capability. Should that object be part of Platform? The IDE? Should the IDE provide an augmented platform where Object  supports such a convenience, (or others, like #break?). I feel that in the development setting, #out or access to Transcript via Object is essential. But that may not carry through to the production environment.

I do not have the capabilities / security background on that level (hehe, once I say something like this online noone will ever hire me again :) ) but I understand this on some level, and am happy you sharing the thoughts. Banning of output streams reminds me of banning sideeffects (I suppose it is related) - how does a program communicate anything useful without it? (no need to answer this misconception of mine, just musing)
 

If we don't have #out, we can certainly  use Transcript in the IDE, as in

Transcript show: 'Hello World'


(2) class HelloWorld = ( 'Hello World' out. )().  This is more like defining Hello World as a program or library. If we want this to work outside the IDE

So this surprised me. How can this code work outside of an IDE? Let me explain why it surprised me - and I am sure a comment will correct another misconception of mine: I thought the term 'library' implies it is a Class, PLUS the ability to package and distribute. I thought that implies presence of the 2 "convention methods" ~#packageLibraryUsingManifest: manifest~ and ~#buildUsing: platform~ . How can a class without those methods be used "outside of the IDE"? Thanks
 
and decide that access to #out is forbidden, we get

class HelloWorld onConsole: Transcript  = (
  Transcript show: 'Hello World'.
)()

(3)
class
HelloApp packageUsing: manifest = () (
public main: platform args: args = (
    'Hello World' out.
))


This is the one I want to start using for now (accepting the out insecurity potential), unless there is a strong reason. Because if I want to talk about new concepts (e.g. using an "imported" third party module, or simply a class Translation), it is clear to browse the additions.
  
or

class HelloApp packageUsing: manifest = (
  | Transcript = manifest Transcript. |
)

public main: platform args: args = (
     Transcript show: 'Hello World'.
))


Now we have Hello World as a full application.

Avoiding the out , yes 

(4) Lastly we have something like your proposal, in which  Hello World is a DOM application - involving things like FFI to JS and GUI. While this is an option, I try and pave over JS whenever possible.

So do I. But as I mentioned, I thought Transcript does not exist in the Wasm version, and did not know about out. So many misconceptions.

Thanks again for your precise comments and help

Milan

Milan Zimmermann

unread,
Jul 13, 2021, 8:57:44 PM7/13/21
to Newspeak Programming Language
During actually trying things, I cannot find Transcript anywhere, eg. 

ide namespacing manifest Transcript

message not understood Manifest Transcript.

Sure I am missing something again. Everything else from my first follow up applies. 

The "''Hello World' out" works and I will use that going ahead for now

Thanks

On Tuesday, 13 July 2021 at 15:48:15 UTC-7 Gilad Bracha wrote:

Gilad Bracha

unread,
Jul 13, 2021, 9:01:43 PM7/13/21
to newspeak...@googlegroups.com
Hi Milan,

a. Transcript does not yet exist in the Web version. A trivial version would leverage  #out:

class Transcript = ()():(
  show: x <String> = (x out)
)

However, we really want something with a UI, integrated into the IDE UI. Not very hard, but I haven't done it.  See https://github.com/newspeaklanguage/newspeak/issues/76.
As it stands, #out writes to the JS console.  This has pros and cons.  One might choose to have it write both the IDE transcript and the JS console. Needs to be worked out.

To your question. Library is an informal term. Any Newspeak module definition (i.e., a top level class) is a library, and to use, it you call its class methods, most likely to instantiate it.
If you want to deploy a module, well, you need to use it via an app (i.e, define something with #packageUsing: and #main:args:), directly or indirectly. 





--
Cheers, Gilad

Milan Zimmermann

unread,
Jul 14, 2021, 12:43:56 AM7/14/21
to Newspeak Programming Language
Gilad:

On Tuesday, 13 July 2021 at 18:01:43 UTC-7 Gilad Bracha wrote:
Hi Milan,

a. Transcript does not yet exist in the Web version. A trivial version would leverage  #out:

class Transcript = ()():(
  show: x <String> = (x out)
)

Wonderfully simple.  

However, we really want something with a UI, integrated into the IDE UI. Not very hard, but I haven't done it.  See https://github.com/newspeaklanguage/newspeak/issues/76.
As it stands, #out writes to the JS console. 
 
Yes. This is good enough for what I want it for.
 
This has pros and cons.  One might choose to have it write both the IDE transcript and the JS console. Needs to be worked out.

Even "simple" things need thoughts and time - like my Hello World head bumps healing :)
 

To your question. Library is an informal term. Any Newspeak module definition (i.e., a top level class) is a library, and to use, it you call its class methods, most likely to instantiate it.

Yes 
If you want to deploy a module, well, you need to use it via an app (i.e, define something with #packageUsing: and #main:args:), directly or indirectly. 

Yes. Or I suppose as a "library module" of another "app module", then this  "library module" would need  "#packageLibraryUsingManifest: manifest" and "#buildUsing: platform", is that right? I want to make that distinction clear in my brain and experiments.

Thanks again for helping out with this thread. I think we can finalize it, if I need other help I will open a new topic. 

And I will share for a review once I write this up - "this" being 'my example based understanding of apps, libraries, and their convention methods, packaging and deployments'

phil jones

unread,
Jul 19, 2021, 11:25:50 PM7/19/21
to newspeak...@googlegroups.com
So how do those "live documents" work. The texts with the embedded cells running snippets of code?

Presumably there's a way to embed running code in a document and have the result of that injected into the document?

Gilad Bracha

unread,
Jul 19, 2021, 11:43:16 PM7/19/21
to newspeak...@googlegroups.com
On Mon, Jul 19, 2021 at 8:25 PM phil jones <inte...@gmail.com> wrote:
So how do those "live documents" work. The texts with the embedded cells running snippets of code?

Yes.  As I mentioned in one of the recent threads, the basic approach is described in


 

Presumably there's a way to embed running code in a document and have the result of that injected into the document?

Yes. You can access the root of the DOM and do with it what you will.  As I discussed last winter, ultimately I want a full WYSWYG rich text editor widget, in which one can embed other widgets, including itself.

--
Cheers, Gilad
Reply all
Reply to author
Forward
0 new messages