Live data from Hacker News

Streem – a new programming language from Matz

github.com

121–130 of 199 posts

Re: Streem – a new programming language from Matz

#121
post #93
post #88

Earlier quoted context omitted.

I prefer {|el| el + 5} more than { _ + 5 } the latter is too implicit for my taste, also I imagine it could become more confusing in a more complex context.

Personally I like it and find it clear. Compare: ary.map(_ * 2) ary.map(x => x * 2) "_" is perhaps an ugly choice of character (frankly I'm not sure why Scala is so obsessed with it, since it's used for so many featurse), but I think the semantics are sensible. Of course, in a more functional language you could perhaps just write ary.map(* 2)

What about a middle ground on swift's syntax?

    Arr.map { $1 * 2 }

Re: Streem – a new programming language from Matz

#122
post #93
post #88

Earlier quoted context omitted.

I prefer {|el| el + 5} more than { _ + 5 } the latter is too implicit for my taste, also I imagine it could become more confusing in a more complex context.

Personally I like it and find it clear. Compare: ary.map(_ * 2) ary.map(x => x * 2) "_" is perhaps an ugly choice of character (frankly I'm not sure why Scala is so obsessed with it, since it's used for so many featurse), but I think the semantics are sensible. Of course, in a more functional language you could perhaps just write ary.map(* 2)

This is not a confusing context, though. This would be a confusing context:

    ary.map(f(_ * 2))

    ==> ary.map(x => f(x * 2)) ?
    ==> ary.map(f(x => x * 2)) ?
How does Scala interpret that one? I have no idea.

Re: Streem – a new programming language from Matz

#123
post #109

Interesting that he chose a C-like syntax after going the complete opposite direction with Ruby.

Huh? Ruby also has a C-like (algol derived) syntax.

The replacement of "}" with "end" etc, is a trivial replacement, not a different type of syntax.

Lisp, Prolog, etc, would be a non-C syntax.

Re: Streem – a new programming language from Matz

#124
post #93
post #88

Earlier quoted context omitted.

I prefer {|el| el + 5} more than { _ + 5 } the latter is too implicit for my taste, also I imagine it could become more confusing in a more complex context.

Personally I like it and find it clear. Compare: ary.map(_ * 2) ary.map(x => x * 2) "_" is perhaps an ugly choice of character (frankly I'm not sure why Scala is so obsessed with it, since it's used for so many featurse), but I think the semantics are sensible. Of course, in a more functional language you could perhaps just write ary.map(* 2)

> I'm not sure why Scala is so obsessed with it, since it's used for so many featurse

You might check out http://stackoverflow.com/a/8001065/3614122. The interesting thing (to me) is that the majority of those are actually the same feature (lifting functions). It's just such a powerful/flexible one that it's often misinterpreted as an entirely new thing in different contexts.

  ary.map(_ * 2)
Is no different than:

  val f = (_:Int) * 2

  ary.map(f)
Or:

  val f: Int => Int = _ * 2

  ary.map(f)
You're just using type-inference in conjunction with lifting. I wrote a blog post on it that's maybe not complete garbage. ;-) http://www.ssmoot.me/scala-s-magical-placeholder

Some of the other examples of the underscore are pattern-matches, which can be used on the LHS of assignment, similar to Erlang. Which comes in handy writing unit-tests. i.e.: If I expect something to return Some[User], and I'm writing a GET->UPDATE integration test, then I'd probably do something like:

  "Update should not blow up" in async {
    val Some(user) = await(db.get(userId))
    val update = user.copy(name = "bob")
    val Success(result) = await(db.put(update))
  }
Extractors/Pattern-Matching is way way up there for me. Much more significant than for-comprehensions. Though you could write the same code like:

  "Update should not blow up with a for-comprehension" in {
  
    val test = for {
      Some(user) 

Re: Streem – a new programming language from Matz

#125

Can someone help explain what's going on here: \"([^\\\"]|\\.) \" [seen here in context]( https://github.com/matz/streem/blob/master/src/lex.l#L49 ). Now it seems to be finding literal strings (so "strings" e.t.c.). That would explain the literal double quotes on either side. so without that we get: ([^\\\"]|\\.) so zero or more repeating versions of [^\\\"]|\\. What I don't understand is why there is the explicit or…

Because if there's a \ you want to skip over the next character, even if it's a ", but if it's not escaped then you want " to be the end of the string.

Re: Streem – a new programming language from Matz

#126
post #93

Earlier quoted context omitted.

Personally I like it and find it clear. Compare: ary.map(_ * 2) ary.map(x => x * 2) "_" is perhaps an ugly choice of character (frankly I'm not sure why Scala is so obsessed with it, since it's used for so many featurse), but I think the semantics are sensible. Of course, in a more functional language you could perhaps just write ary.map(* 2)

This is not a confusing context, though. This would be a confusing context: ary.map(f(_ * 2)) ==> ary.map(x => f(x * 2)) ? ==> ary.map(f(x => x * 2)) ? How does Scala interpret that one? I have no idea.

It doesn't. It's invalid code in most (all?) cases.

  scala> val f: Int => Int = _ - 1
  f: Int => Int = 

  scala> val ary = Array(1,2,3)
  ary: Array[Int] = Array(1, 2, 3)

  scala> ary.map(f(_ * 2))
  :10: error: missing parameter type for expanded function ((x$1) => x$1.$times(2))
              ary.map(f(_ * 2))
                        ^
You can't think of "_" like a placeholder. It's not. It's to lift an argument of a function.

So simplify it: map in this context wants a Function[Int, Int] right? So f(_ * 2) must return a Function[Int,Int]. But it doesn't probably. _ is lifting some argument out of whatever f is. If you assume _ is an Int, does f take a Function[Int,Int]? No. It takes an Int. So there's no way to parse this that makes sense. It's not just "I have a stack of vars, pull one off the stack and bind it every time I write an underscore, reading left to right". That would be some AST generative grammar hack. That's not what the underscore is. It's simpler and more consistent than that.

What you're probably looking for instead is Function Composition. So something like:

  scala> ary.map(f compose(_ * 2))
  res10: Array[Int] = Array(1, 3, 5)
So why does that work? Because we were able to compose f() into a larger function that satisfies the signature of the argument map[T](Int => T) requires. A lot like a Stream conceptually.

(Is it correct to say in this context f() is a Monad? I'm not sure, I need to sit down and grok the category stuff sometime...)

Or you can write it the long way (calling f inside a new function). But instead of defining "steps" you'd be creating a new imperative function and driving the stack.

Re: Streem – a new programming language from Matz

#127

Earlier quoted context omitted.

The one-liner is valid Python. It's slightly non-idiomatic in that it uses a list-comprehension where a generator expression would do, and uses range instead of xrange (in Python 2.x; in 3.x range is the idiomatic alternative).

it's also non-idomatic in that is uses string-multiplication and ==0 where an "if not" ternary expression would be much cleaner.

Yes, a ternary would be clearer, to me. I wasn't sure what was happening with the * (and thought maybe it was some use of the "whatever star" in Perl 6, when I was thinking it might be Perl 6, though it doesn't look like any use of the whatever star I've seen), but I just assumed it made sense to someone who knew the language well. It's been a decade since I worked in Python with any regularity.

Re: Streem – a new programming language from Matz

#128

Earlier quoted context omitted.

That manual is possibly the single most useful technical document that I have ever read. It has enabled me to write extremely powerful programs that no one I know can understand. It would however be nice to have a tool with similar power but simpler, more comprehensible syntax. One of the other commenters linked to an interesting document on sam, which has a better control flow but equally arcane syntax.

I think that stream-oriented languages are doomed to have an arcanic syntax. Streams are a non-trivial construction, after all.

I think I don't believe you. Look at the car and house example above. Is that arcane?

Re: Streem – a new programming language from Matz

#129
post #124
post #93

Earlier quoted context omitted.

Personally I like it and find it clear. Compare: ary.map(_ * 2) ary.map(x => x * 2) "_" is perhaps an ugly choice of character (frankly I'm not sure why Scala is so obsessed with it, since it's used for so many featurse), but I think the semantics are sensible. Of course, in a more functional language you could perhaps just write ary.map(* 2)

> I'm not sure why Scala is so obsessed with it, since it's used for so many featurse You might check out http://stackoverflow.com/a/8001065/3614122 . The interesting thing (to me) is that the majority of those are actually the same feature (lifting functions). It's just such a powerful/flexible one that it's often misinterpreted as an entirely new thing in different contexts. ary.map(_ * 2) Is no different than: val…

Your last example code is missing a closing-brace. I know no Scala, though, so I'm actually not sure where it should go.

Re: Streem – a new programming language from Matz

#130

Earlier quoted context omitted.

it's also non-idomatic in that is uses string-multiplication and ==0 where an "if not" ternary expression would be much cleaner.

Yes, a ternary would be clearer, to me. I wasn't sure what was happening with the * (and thought maybe it was some use of the "whatever star" in Perl 6, when I was thinking it might be Perl 6, though it doesn't look like any use of the whatever star I've seen), but I just assumed it made sense to someone who knew the language well. It's been a decade since I worked in Python with any regularity.

I would probably use a named function call in real code, but the 'text * (expr == 0)' idiom is pretty clear to me as a way to conditionally include text based on whether a condition is true or not.
Post reply on HN