News for hackers. Stuff that matters.
Re:PlsExplain: A small dynamic programming language where ev... by AnimaLibera on Sunday August 22, 2021 @08:02PM (#28270924)
Ah a LangJam entry ^^ There are plenty more original ideas for one to check out at https://github.com/langjam/jam0001 Teams had 48h to design and implement a programming language based on the theme "first-class comments".
Re:PlsExplain: A small dynamic programming language where ev... by macintux on Sunday August 22, 2021 @09:09PM (#28271316)
Thanks for the pointer. I thought this was quite interesting without realizing it had been created in 48 hours. Remarkable.

This language has been encouraging me to ruminate on data provenance and traceability tonight.

Re:PlsExplain: A small dynamic programming language where ev... by Bootvis on Monday August 23, 2021 @01:36AM (#28272618)
It would be interesting to apply this idea to the columns of a data frame.
Re:PlsExplain: A small dynamic programming language where ev... by p4bl0 on Monday August 23, 2021 @03:35AM (#28273169)
This is a fun idea, but it generates comments that are typically the ones which should not exists in actual code, because they do not add any useful information. Thinking about it I'm not sure it is possible to do better. If the comment can be automatically generated from the source code, then the source code itself will necessarily a be more precise version, making the comment useless. The benefit here is that at least the comments are automatically updated at the same time as the code…
Re:PlsExplain: A small dynamic programming language where ev... by BulgarianIdiot on Monday August 23, 2021 @04:56AM (#28273639)
> This is a fun idea, but it generates comments that are typically the ones which should not exists in actual code, because they do not add any useful information

The point is attaching meta info to values which aren't pointless. Say:

    weight = 42 /* pounds */;
It's kinda like types, but without the type checks. I'm not purely sarcastic, because boxing values within objects so they have a type has drawbacks.

That said, there are better way of typing values without boxing them.

Re:PlsExplain: A small dynamic programming language where ev... by sparsely on Monday August 23, 2021 @07:41AM (#28274408)
F# does exactly this, except it understands the rules of units cancelling etc.
Re:PlsExplain: A small dynamic programming language where ev... by Anunayj on Monday August 23, 2021 @11:31AM (#28277383)
Woah TIL. I've been looking for a similar language, something that I can do Physics in without having to worry about units/constants. Till now I've used WolframAlpha or just Google. Do you think F# is suited for this, or do you suggest other alternatives?
Re:PlsExplain: A small dynamic programming language where ev... by sparsely on Thursday August 26, 2021 @09:55AM (#28314964)
F# definitely has the most complete implementation that I've seen, I'm sure other languages would let you hack something together though.

https://docs.microsoft.com/en-us/dotnet/fsharp/language-refe...

Re:PlsExplain: A small dynamic programming language where ev... by micvbang on Monday August 23, 2021 @04:01AM (#28273332)
This reminds me of https://imgur.com/gallery/dZe8k :)
Re:PlsExplain: A small dynamic programming language where ev... by mike_hock on Monday August 23, 2021 @04:17AM (#28273414)

    /** Half the number **
     *********************
     ** Multiplies the number by one half (0.5)
     */
    float x2 = x * 0.5F;
    
    /** Copy the number **
     *********************
     ** Stores a copy of the number in a new variable
     */
    float y = x;
    
    /** Pointer cast **
     ******************
     ** Take the address of the number,
     ** cast the pointer to a pointer pointing to long,
     ** and dereference that pointer,
     ** then store the result in a new variable.
     */
    long i  = * ( long * ) &y;
    
    /** Subtract and shift **
     ************************
     ** Shift the number one bit position to the right,
     ** then subtract the result from the constant 0x5f3759df
     */
    i  = 0x5f3759df - ( i >> 1 ); 
    
    /** Pointer cast **
     ******************
     ** Take the address of the number,
     ** cast the pointer to a pointer pointing to float,
     ** and dereference that pointer,
     ** then store the result in an existing variable.
     */
    y  = * ( float * ) &i;
    
    /** Multiply twice, subtract and multiply again **
     *************************************************
     ** Multiplies the number by itself,
     ** then multiplies the result by the other number,
     ** then subtracts that from the constant three halfs (1.5),
     ** then multiplies that by the number.
     ** The original number.
     ** The first number.
     ** You know what I mean.
     */
    y  = y * ( 1.5F - ( x2 * y * y ) );
    
    
    /** Multiply twice, subtract and multiply again **
     *************************************************
     ** Multiplies the number by itself,
     ** then multiplies the result by the other number,
     ** then subtracts that from the constant three halfs (1.5),
     ** then multiplies that by the number.
     ** The original number.
     ** The first number.
     ** You know what I mean.
     ** This can be removed.
     */
    //  y  = y * ( 1.5F - ( x2 * y * y ) );
    
    /** Return from function **
     **************************
     ** Returns the number
     */
    return y;
Re:PlsExplain: A small dynamic programming language where ev... by gregwebs on Monday August 23, 2021 @07:43AM (#28274426)
Actually this would be quite useful not for the traditional role of comments but instead to debug program flow.
Re:PlsExplain: A small dynamic programming language where ev... by still_grokking on Sunday August 22, 2021 @08:29PM (#28271086)
Does this LangJam take suggestions for tasks?

I would like to see the outcome of people trying to design a language with first-class scope.

Re:PlsExplain: A small dynamic programming language where ev... by shakna on Monday August 23, 2021 @02:13AM (#28272767)
I'm in the process of putting together a scripting language where everything has its own scope [0].

Just to scratch my own itch, and it's stringly so I could throw it together in about 3 days.

If that is mildly interesting to you.

[0] https://git.sr.ht/~shakna/scriptlang

Re:PlsExplain: A small dynamic programming language where ev... by still_grokking on Monday August 23, 2021 @12:31PM (#28278371)
I had a look at the readme but don't see the "first class scope" part.
Re:PlsExplain: A small dynamic programming language where ev... by shakna on Monday August 23, 2021 @06:13PM (#28282665)
> Every function call receives its own scope

Which you can also see here [0], in the interpreter, or here[1] for the "let" example. Everything gets it's own scope, with only "global!" and "set!" being able to escape that. (And all the usual flow control like "if", "cond", "for", etc. are just ordinary function calls.)

[0] https://git.sr.ht/~shakna/scriptlang/tree/master/item/script...

[1] https://git.sr.ht/~shakna/scriptlang/tree/master/item/exampl...

Re:PlsExplain: A small dynamic programming language where ev... by still_grokking on Monday August 23, 2021 @09:21PM (#28284096)
Sorry, maybe I'm ignorant, but I still don't see it.

What I see is: The scope is not a first-class object. You can't "touch" it.

I see variable shadowing. And I think something that's called "dynamic scope"—or maybe it's just references, not sure.

I'm not 100% sure even what "first-class" scope would look like. I don't know any language that claims having it. I have a few ideas but would like to see some more to find out whether this idea make any sense at all. It's not in the ballpark of "first-class comments" and could be even useful. Maybe. But to know that we would need to have some language to play with.

Re:PlsExplain: A small dynamic programming language where ev... by shakna on Monday August 23, 2021 @10:49PM (#28284612)
If I'm understanding what you're calling first-class scope, then Lua's environments would count as a well-developed language with first class scope. Sandboxing Lua (outside of Luajit) is trivial, for example, because you just bind a given environment to a given function. [0]

Scope in my scripting language is also similar - you can definently touch it. That's how "set!" allows you to create a variable, for example. Assignment isn't special. set! is reaching into the scope above itself to place the variable, otherwise it wouldn't be accessible after the set! call. But it is just a function call. (And there's a couple other things like scopedepth to help you index a given scope).

[0] https://www.lua.org/pil/14.html

Re:PlsExplain: A small dynamic programming language where ev... by still_grokking on Wednesday August 25, 2021 @03:58PM (#28306160)
Thank you for the pointer to Lua! Will have a look.

Yes, "scope" is in the end the evaluation environment of some funktion. Usually it's not a first-class object in a particular language, and only available implicitly.

Having it first-class would mean being able to directly manipulate and pass function environments.

Like I said, I'm not sure this makes sense at all. But maybe it could open up some possibilities.

(I came up with the general idea when thinking about what the "implicit scope" in Scala is, or could be seen as).

Re:PlsExplain: A small dynamic programming language where ev... by Strilanc on Sunday August 22, 2021 @08:04PM (#28270934)
This is a very interesting idea. I worry that the runtime overhead might be enormous (adding two numbers involves concatenating strings), and cause the space usage of the program to depend on its execution time. I think it's still missing something, like maybe keeping sizes of explanations reasonable by using a machine learned summarizer.

Basically... bang on for a code jam language.

Re:PlsExplain: A small dynamic programming language where ev... by vnorilo on Monday August 23, 2021 @01:44AM (#28272656)
A serious implementation would probably use a binary tree (such as twine [1]), so it would basically boil down to creating a node for each operation. Still expensive, but if you imagine integrating it with, say, Python interpreter, I don't think it would dominate execution time. Memory might be another matter.

1: https://llvm.org/doxygen/classllvm_1_1Twine.html#details

Re:PlsExplain: A small dynamic programming language where ev... by choeger on Monday August 23, 2021 @02:43AM (#28272909)
I think there is an error in one of the examples, or the implementation is odd:

>>> print(x?) /* the number 4.0 */

Should yield

/* the number 4.0 */ /* a comment */

Right?

Re:PlsExplain: A small dynamic programming language where ev... by ojbyrne on Sunday August 22, 2021 @10:15PM (#28271694)
Can we get the title changed? I thought this had to do with dynamic programming, it’s actually a dynamically typed programming language.
Re:PlsExplain: A small dynamic programming language where ev... by divs1210 on Monday August 23, 2021 @02:28AM (#28272854)
"dynamic programming" and "dynamic programming language" and "dynamically typed programming language" are all different terms and mean different things.
Re:PlsExplain: A small dynamic programming language where ev... by InternetPerson on Monday August 23, 2021 @09:47AM (#28275637)
"dynamic programming" refers to something different. In practice, it often just means "solving a problem recursively using a memo table." But wikipedia obviously does it more justice [1].

It's a terrible name, and even the person who came up with the name admits that it's terrible: "The word dynamic was chosen [...] because it sounded impressive."

[1] https://en.wikipedia.org/wiki/Dynamic_programming

Re:PlsExplain: A small dynamic programming language where ev... by InternetPerson on Monday August 23, 2021 @09:48AM (#28275643)
Derp. I misread both parent comments. Please disregard.
Re:PlsExplain: A small dynamic programming language where ev... by dleslie on Sunday August 22, 2021 @11:54PM (#28272176)
This seems like it would make a brilliant extension for literate programming; a self documenting REPL paired with literate source! And, of course, trivially optimized out of necessary.
Re:PlsExplain: A small dynamic programming language where ev... by neilv on Monday August 23, 2021 @03:47AM (#28273249)
This is a docstring annotation on a value (rather than a definition)? And what we recognize as comment syntax from C could also equivalently be, say, an `anno` keyword or punctuation, followed by a more familiar string literal?

  let x = 40 + 2 /* the number fourtytwo */;

  let x = 40 + 2 anno "the number fourtytwo";

  let x = 40 + 2 @"the number fourtytwo";
Re:PlsExplain: A small dynamic programming language where ev... by furstenheim on Monday August 23, 2021 @12:06AM (#28272237)
Not as extreme as PlsExplain. But in JavaScript you can also describe what you log using babel https://github.com/furstenheim/babel-plugin-meaningful-logs
Re:PlsExplain: A small dynamic programming language where ev... by Flocular on Monday August 23, 2021 @11:00AM (#28276815)
Instead of calling them comments (which to me are very much not interpreted) maybe make "documentation" a first class object of the language instead?
Re:PlsExplain: A small dynamic programming language where ev... by clows on Monday August 23, 2021 @03:43AM (#28273227)
Looks like a decent corporate javadoc autocommenter.
Re:PlsExplain: A small dynamic programming language where ev... by junon on Sunday August 22, 2021 @08:03PM (#28270927)
Perhaps I missed it in the readme but what problems does it aim to solve (even if it is a toy language)?

EDIT: Oh, another user pointed out the origin for it.

Re:PlsExplain: A small dynamic programming language where ev... by still_grokking on Sunday August 22, 2021 @08:25PM (#28271060)
Looks like an ad-hoc dependly typed language, but dynamic.