Live data from Hacker News

Bog – small, strongly typed, embeddable language

github.com

21–30 of 55 posts

Re: Bog – small, strongly typed, embeddable language

#22

Thank you for posting this. > let {print} = import "std.io" An idea obvious in hindsight that I hadn't thought before - if import returns an environment and let can destructure, then a pattern match can bind an explicit subset of that import. Something like: `(let {print read} (import io) (print (read)))` Further down I find essentially that example (with input instead of read) and destructuring assignment within fun…

Isn't this exactly what CommonJS does/did?

No, you're thinking of `destructuring`. CommonJS was "just" a common format for defining/importing modules in a NodeJS environment (via `module.exports` and `require`), eventually being used for packaging frontend "applications" as well, popularized by Browserify.

To expand, the following was common before destructuring but with CommonJS:

    var some_func= require('some_module').some_func
Which, as you know, would probably usually be done like this today, where we have destructuring:

    let {some_func} = require('some_module')

Re: Bog – small, strongly typed, embeddable language

#23
post #10
post #8

Pretty interesting. I'm a professional user of Lua, and while I love it, I really get frustrated at a lot of aspects of it, especially how loose the typing is. I've long wished there were more strongly typed alternatives, but just nothing compares to the performance, stability, and quality of documentation of Lua. I'm not sure how I would embed this in a non-Zig project, though.

There’s a C embed example in the examples folder

Nice, thanks. Looks pretty reasonable, but I'd really have to learn some zig myself to be fully comfortable using it, I think.

Re: Bog – small, strongly typed, embeddable language

#24
post #14

Somewhat related is yesterday's post about the Cyber programming language, also built on Zig and also embeddable: https://news.ycombinator.com/item?id=34553236 (Not affiliated with either, just can be easy to miss stories on here sometimes, and I figured anyone interesting in Bog might also be interested in Cyber)

Looking at the two of them, both awesome projects, not a competition but here are a few things I noticed. Cyber seems to have pretty good documentation [0] (maybe Bog does too but I didn't find too much from the readme. For example, you can see Bog has a GC and its standard library supports JSON, but memory management and non-scalar data structures aren't mentioned in the Bog readme).

Cyber also seems to be under more active development at the moment.

https://github.com/vexu/bog/graphs/contributors

https://github.com/fubark/cyber/graphs/contributors

[0] https://github.com/fubark/cyber/blob/master/docs/docs.md

Re: Bog – small, strongly typed, embeddable language

#26

Love how this language is explained with code only.

Is it just me or is that a terrible “hello world”? I get that they’re trying to illustrate a few features but the whole point of hello world is that it is the absolute most simple program. Why put the string world into a variable named world just to show that you can insert a variable into a string? It looks so confusing.

Re: Bog – small, strongly typed, embeddable language

#27
post #6

Thank you for posting this. > let {print} = import "std.io" An idea obvious in hindsight that I hadn't thought before - if import returns an environment and let can destructure, then a pattern match can bind an explicit subset of that import. Something like: `(let {print read} (import io) (print (read)))` Further down I find essentially that example (with input instead of read) and destructuring assignment within fun…

Something I hate about about c is that you don't know where the hell somefunc() came from. Some languages have foo.somefunc() which I think works quite well although iffooisrealllylong.function() is a risk. I suppose this gets you the best of both worlds. Although using let does seem a bit weird to me. It seems conceptually misleading.

> Something I hate about about c is that you don't know where the hell somefunc() came from.

I think you mean something you hate about not using an IDE with the language. One can do `from onoz import *` in python and Java to have a similar "wait, where did do_magic() come from?" experience, and then Scala will see your wildcard import and raise you implicit methods, which can die in a raging fire tornado

Re: Bog – small, strongly typed, embeddable language

#28
post #7

Thank you for posting this. > let {print} = import "std.io" An idea obvious in hindsight that I hadn't thought before - if import returns an environment and let can destructure, then a pattern match can bind an explicit subset of that import. Something like: `(let {print read} (import io) (print (read)))` Further down I find essentially that example (with input instead of read) and destructuring assignment within fun…

Funny, I find this syntax very obtuse: it looks to me like "print" is being defined as, well, the print function, through a very roundabout name collision. What happens if there is a typo and the code says: let {ptint} =... What error message comes up?

It's not roundabout. Namespaces in many languages are simply dictionaries/mappings of strings to objects, with the restriction that the strings must conform to a variable name standard.

There's not much difference between `obj.attr` and `obj['attr']`.

Re: Bog – small, strongly typed, embeddable language

#29
post #6

Thank you for posting this. > let {print} = import "std.io" An idea obvious in hindsight that I hadn't thought before - if import returns an environment and let can destructure, then a pattern match can bind an explicit subset of that import. Something like: `(let {print read} (import io) (print (read)))` Further down I find essentially that example (with input instead of read) and destructuring assignment within fun…

Something I hate about about c is that you don't know where the hell somefunc() came from. Some languages have foo.somefunc() which I think works quite well although iffooisrealllylong.function() is a risk. I suppose this gets you the best of both worlds. Although using let does seem a bit weird to me. It seems conceptually misleading.

This is true that there is no language feature to enforce this. But this can be worked around by enforcing naming functions with adequate prefixes, which is a very common approach, if not a best practice.

Re: Bog – small, strongly typed, embeddable language

#30
post #12

Earlier quoted context omitted.

Have you heard of Teal ( https://github.com/teal-language/tl )? It's like typescript for Lua made by Hisham. It also has the concept of declaration files so you can import (and type) existing Lua modules if needed.

I haven't, but I might have to do a lot of work to get it working, as my typical use of Lua is deeply embedded and customized, and doesn't allow any filesystem access. I will definitely look into that, though, thank you. The only real Lua dialect I'm familiar with in that area is Moonscript.

There's many different approaches to typed Lua:

- https://luau-lang.org (interpreted / sandboxed)

- https://terralang.org (JIT interpreted)

- https://nelua.io (Lua -> C)

- https://typescripttolua.github.io/ (TS -> Lua)

- https://github.com/teal-language/tl (Teal -> Lua)

- https://github.com/sumneko/lua-language-server (IDE only typing)

With minimum effort you can get a lot of benefit from using Sumneko's Lua language server.

Post reply on HN