[HN Gopher] Wren is a small, fast, class-based concurrent script...
       ___________________________________________________________________
        
       Wren is a small, fast, class-based concurrent scripting language
        
       Author : jay_kyburz
       Score  : 42 points
       Date   : 2020-06-27 08:57 UTC (14 hours ago)
        
 (HTM) web link (wren.io)
 (TXT) w3m dump (wren.io)
        
       | dang wrote:
       | If curious see also
       | 
       | 2018 https://news.ycombinator.com/item?id=16945227
       | 
       | 2016 https://news.ycombinator.com/item?id=11611661
       | 
       | 2015 https://news.ycombinator.com/item?id=8826060
        
       | wespiser_2018 wrote:
       | Wow, this would be ideal for me to write loadtests in! In broad
       | strokes, I just want to spin up N threads making request after
       | request, in an event loop with basic tracking. Is there a JSON or
       | Network library available yet?
        
       | jbverschoor wrote:
       | Looks like ruby with {}. Performs like ruby
        
       | brundolf wrote:
       | > The VM implementation is under 4,000 semicolons.
       | 
       | > Lightweight fibers are core to the execution model and let you
       | organize your program into a flock of communicating coroutines.
       | 
       | > Wren is intended for embedding in applications. It has no
       | dependencies, a small standard library, and an easy-to-use C API.
        
       | xscott wrote:
       | Wren seems like a really clean alternative to a language like
       | Python, but it makes one mistake that really drives me nuts. In
       | order to provide binary operators, you must implement a method on
       | the left object. From the documentation [0]:
       | 
       | > The left operand is the receiver, and the right operand gets
       | passed to it. So a + b is semantically interpreted as "invoke the
       | +(_) method on a, passing it b".
       | 
       | This means that if you want to implement complex numbers, or
       | matrices, or a bunch of other useful stuff, you'd have to be able
       | to extend the type on the left (which you didn't write). You
       | really want to be able to do things like:                   var z
       | = Complex.new(1.0, 2.0)         var result = 3.0 - z
       | var A = Matrix.ident(3, 3)         var scaled = 4.0*A
       | 
       | Python hacks around this by having "right' versions of these
       | methods too. It's kind of ugly - if the left object fails to
       | support the operator method (__sub__ or __mul__) with the right
       | type, the interpreter looks for a __rsub__ or __rmul__ operator
       | on the right object to try. Ugly, but it works.
       | 
       | C++ works around this a much better way: You can either have the
       | operator method on the left object, or have an overloaded
       | operator function that isn't tied to either object.
       | 
       | Rust puts the operators on the left object too, but in some cases
       | you _can_ add methods /trait specializations to left classes.
       | Unfortunately, Rust doesn't let you do this with generics, but
       | that's a longer more complicated topic.
       | 
       | Maybe there's some way Wren lets you tack on additional methods
       | to the builtin Num class (monkey patching), but I couldn't find
       | it. I would love an elegant alternative to Python, but this is
       | enough of an issue that it keeps me from using Wren.
       | 
       | [0] - https://wren.io/method-calls.html#operators
        
         | byroot wrote:
         | You also have the Ruby solution of calling a `coerce` [0]
         | method on the right hand side.
         | 
         | [0] -
         | https://github.com/ruby/ruby/blob/0703e014713ae92f4c8a2b31e3...
        
         | scythe wrote:
         | Lua addresses this problem by having metamethods, with a
         | special way of failing over when operators meet a type error:
         | 
         | https://www.lua.org/manual/5.3/manual.html#2.4
         | 
         | >If any operand for an addition is not a number (nor a string
         | coercible to a number), Lua will try to call a metamethod.
         | First, Lua will check the first operand (even if it is valid).
         | If that operand does not define a metamethod for __add, then
         | Lua will check the second operand. If Lua can find a
         | metamethod, it calls the metamethod with the two operands as
         | arguments, and the result of the call (adjusted to one value)
         | is the result of the operation. Otherwise, it raises an error.
        
           | xscott wrote:
           | Thank you for the link, but I'm not sure this solves the
           | problem. I mean, what if Abbie makes complex numbers, so she
           | provides a metamethod to work with the builtin number type.
           | Then Bobby wants to build on Abbie's work and add matrices.
           | Lets say Abbie's complex type is on the left, but her
           | metamethod doesn't know anything about matrices... Bobby is
           | willing to support complex numbers multiplied with matrices,
           | but the matrix metamethod never gets called:
           | z = complex(1, 2)         A = ident(3, 3)         -- Won't
           | this next line call the wrong metamethod?         X = z*A
           | 
           | For a dynamicly typed language, I think you'd want something
           | like multimethods to do this cleanly. (Or something like
           | Python's dirtier approach)
        
       | darksaints wrote:
       | I believe this language was originally the creation of the guy
       | who wrote the crafting interpreters book, but it definitely looks
       | like it has grown well beyond his influence.
        
       | da39a3ee wrote:
       | > Wren is a scripting language.
       | 
       | As far as I know "scripting language" doesn't have a widely-
       | agreed upon definition and we should all stop using it.
       | 
       | If anyone were to ask me, I'd say that a "script" is a program
       | that contains a sequence of commands. It executes transiently for
       | some side effect, as opposed to creating a persistent process
       | responding to events.
       | 
       | So for example, bash is clearly a scripting language, and if one
       | is being rude about the appropriate uses for perl, then perl
       | would be too. Python can be use for "scripting" but certainly
       | isn't in general a scripting language by this definition. And I
       | don't really think "scripting language" is a helpful term for
       | Javascript, since it's most important role by far is in as an
       | event-driven persistent process. However, some people (especially
       | old-school C-programmer types) use "scripting language" to mean
       | an interpreted language, I think.
       | 
       | I think for Wren, maybe it's referring to a usage of "scripting"
       | that C programmers associate with Lua?? None of the things it
       | mentions are things that I personally associate with the word
       | "scripting":
       | 
       | > Wren is intended for embedding in applications. It has no
       | dependencies, a small standard library, and an easy-to-use C API.
       | It compiles cleanly as C99, C++98 or anything later.
       | 
       | Or is the idea that both Lua (and thus Wren) and Javascript are
       | "scripting" languages in the sense that they augment an
       | executable written in a "proper" language with additional run-
       | time functionality? If so, then that's interesting but I don't
       | think many people get it (it only occurred to me while writing
       | this) and we should clarify the terminology.
        
         | andrewflnr wrote:
         | I understand about avoiding unclear terms, but I think
         | "scripting language" actually does serve a useful purpose as an
         | umbrella term for all those kinds of languages. It's not
         | technically precise, but if you describe a language as "a
         | scripting language", it does clear away a large part of the
         | design space (not Haskell, C, Forth, or J) and tells you that
         | this is meant to be user-friendly as opposed to performant,
         | terse, high-assurance, etc. That's worth something. Of course
         | if someone is still interested, then you want to get more
         | precise pretty quickly. I think Wren does well enough at that
         | on its landing page.
        
         | caditinpiscinam wrote:
         | I think of it, very generally, as: scripting language = writing
         | a 10 line program isn't a chore; non-scripting language:
         | writing a 1000 line program isn't a chore
        
       | nerdponx wrote:
       | I'd be interested in if this is comparable to Gleam, a BEAM-based
       | scripting language, that I discovered through HN.
        
         | dnautics wrote:
         | I believe gleam is a compiled language, and no more of a
         | scripting language than say erlang (with escript) or elixir
         | (via .exs files).
        
       | vaibhavthevedi wrote:
       | Looks nice. It reminds very much of C and C++ programming. What
       | are some of its use cases?
        
         | Avshalom wrote:
         | I think it got it's start as part of https://luxeengine.com/
         | which transitioned away from Haxe
        
           | skybrian wrote:
           | Wren was originally written by Bob Nystrom, author of
           | Crafting Interpreters. He recently handed it off to another
           | maintainer.
        
         | skybrian wrote:
         | If you're writing an application in C or C++ and want to embed
         | a scripting language, and you think Lua is kinda weird and
         | would prefer a more straightforwardly object-oriented language,
         | then Wren may be worth trying.
         | 
         | But I think there is only one active maintainer so you should
         | be prepared to write your own patches if you need to fix
         | something.
        
         | dejv wrote:
         | I am building tool for generating PDFs (https://docula.app) and
         | I am using Wren to allow user scripts: things like show/hide
         | label on some value or maybe display number in red when the
         | value is > 0 and green otherwise. I was thinking about using
         | Lua, but Wren seems more approachable to me.
        
       | MR4D wrote:
       | Looks like what JavaScript would be like without all the baggage
       | from the '90's.
        
       ___________________________________________________________________
       (page generated 2020-06-27 23:00 UTC)