News for hackers. Stuff that matters.
Re:ngn/k, an AGPL K interpreter by warpech on Friday January 10, 2020 @03:54AM (#22009483)
If you find it unbelievable that code like this is written by hand, read this short explanation about “a very unusual style of C” [1].

Fastai has a guide how to write Whitney-style code in Python [2].

Thre is a relevant thread in HN [3].

[1] https://github.com/kevinlawler/kona/wiki/Coding-Guidelines#t...

[2] https://docs.fast.ai/dev/style.html

[3] https://news.ycombinator.com/item?id=19481505

Re:ngn/k, an AGPL K interpreter by userbinator on Friday January 10, 2020 @08:17AM (#22010703)
For those who want to try understanding APL-styled C, I recommend starting off with this:

https://code.jsoftware.com/wiki/Essays/Incunabulum

I think a lot of the reason people have difficulty is that you need to read the macros first; jumping into the middle won't make any sense. The macros are very mnemonic and there's only 5 of them. For example, I found the DO macro to be particularly elegant because it expresses "repeat something n times", and one of the features of array languages which makes them terse and powerful is this implicit repetition.

Re:ngn/k, an AGPL K interpreter by saagarjha on Friday January 10, 2020 @04:24AM (#22009630)
This isn't even unusual "I want to write K in C" style, it's specifically being annoying: https://bitbucket.org/ngn/k/src/master/m.c. I mean, for goodness' sake, it's pivoting the stack in x86_64 assembly to implement _start!
Re:ngn/k, an AGPL K interpreter by ngnk on Friday January 10, 2020 @04:39AM (#22009715)
any ideas for a more compact and efficient way to get argc and argv on both linux and freebsd without bringing in libc?
Re:ngn/k, an AGPL K interpreter by kick on Friday January 10, 2020 @05:02AM (#22009843)
Thanks for writing/freeing this! I've had a lot of fun with it since a friend first pointed out that it had been released under a libre license.
Re:ngn/k, an AGPL K interpreter by pja on Friday January 10, 2020 @06:11AM (#22010162)
Nope :)

But http://dbp-consulting.com/tutorials/debugging/linuxProgramSt...

does suggest zeroing the top-most frame (%ebp) and making sure the stack is 16-byte aligned might also be worth doing. (Possibly it’s already 16-byte aligned already because you jmp to main instead of calling it though?)

Re:ngn/k, an AGPL K interpreter by ngnk on Friday January 10, 2020 @07:02AM (#22010376)
that's a good read, thanks. afaik zeroing %rbp here plays no role other than to assist debuggers. i'm not sure if alignment makes any measurable difference. if it does, it'll be worth doing. i jmp to main() because i wrote it and i know it never returns. it exit()-s.
Re:ngn/k, an AGPL K interpreter by saagarjha on Friday January 10, 2020 @07:06AM (#22010394)
> afaik zeroing %rbp here plays no role other than to assist debuggers.

Yep, it marks function frame boundaries. If you don't particularly care, you may want to consider compiling with -fomit-frame-pointer and the compiler will return this register back to the set of general purpose ones for it to use.

> i'm not sure if alignment makes any measurable difference. if it does, it'll be worth doing.

It will if you end up emitting any SSE instructions, because they will cause loads and stores that need to be aligned.

Re:ngn/k, an AGPL K interpreter by 3xblah on Friday January 10, 2020 @06:19AM (#22010202)
I use _getenv in k3

   a=arg1 b=arg2 k c.k
Re:ngn/k, an AGPL K interpreter by saagarjha on Friday January 10, 2020 @04:51AM (#22009772)
Portably? No.
Re:ngn/k, an AGPL K interpreter by duskwuff on Friday January 10, 2020 @05:02AM (#22009845)
Given that the interpreter makes system calls directly using inline assembly [1], I suspect that any hope of portability went out the window long ago.

[1]: https://bitbucket.org/ngn/k/src/b54eb5cfea5eb821fe1de68d2a8a...

Re:ngn/k, an AGPL K interpreter by ngnk on Friday January 10, 2020 @05:48AM (#22010059)
across architectures: you're right, as of now it's x86_64 only

across operating systems: it works on linux and freebsd as-is (thanks bakul), and with a few changes on windows+libc (thanks ktye) - https://github.com/ktye/i/tree/master/_/ngn though i personally never use windows

Re:ngn/k, an AGPL K interpreter by mark_l_watson on Friday January 10, 2020 @08:19AM (#22010711)
Thanks, especially for the fastai style link. I am currently finishing a book [1] that uses the Hy language (hylang) which is a Lisp wrapper on Python. I am going to revisit my code examples, informed by Jeremy’s ideas. Hy is really just a simple mapping of Python to Lisp (syntax very much like Clojure) so most of his style ideas carry over.

[1] https://leanpub.com/hy-lisp-python

Re:ngn/k, an AGPL K interpreter by msla on Wednesday January 15, 2020 @06:34AM (#22053372)
I wish they'd release the source of the obfuscator they used.