Better HN
topnewbestaskshowjobs
Log inSign up

ericbb

149 karma · joined Nov 6, 2009 (17y ago) · 117 submissions

https://norstrulde.org

eric.bergstrome@gmail.com

Submissions

comment 13y ago · link · parent

You claim (as I understand):

    (Java + Clojure) > Go && (Java + Scala) > Go
That stance seems to require a low weight on the cost of conceptual and tool-chain overhead. I haven't measured, but I'd guess that the language spec of Go is shorter than the specs of each of those other languages.

Edit: Fix spelling of "Clojure".

comment 13y ago · link · parent

> Now, you might want to ... acquaint yourself with [dataflow variables and declarative concurrency] because [they are] the centre-piece of Go's language features.

Not so. Go has native support for neither dataflow variables nor declarative concurrency. Go does have native support for message-passing concurrency--but that's different.

comment 13y ago · link · parent

Alexander Burger indents his PicoLisp code more along the lines you describe. Example: http://rosettacode.org/wiki/Execute_Brain****#PicoLisp

comment 13y ago · link · parent

> You do. (Or in reality, the whole world since the point of Mega is to share files.)

That implication makes no sense to me. Why would you ever share a private key?

The trust question is more about public keys. Do you trust that the key you think is your friends public key really is? And that's what key-signings are for.

The screenshot shows in-browser key generation but there's no reason I can think of that they should not accept keys generated by GPG or similar. Generate your keypair as securely as you can and however you like--and then only submit your public key to the Mega site.

comment 14y ago · link · parent

What's "code-as-procedure" supposed to be? Denotation?

And how could "code-as-procedure" fail to be easy to express using "code-as-data"?

Isn't it more essential that "code-as-data" should be easy to express in "code-as-text"? (As that's where languages like Lisp and ML, that have quasiquotation, excel).

comment 14y ago · link · parent

I would argue that there is an obvious correct answer for array indexing and nil pointer dereference. Go could have been designed to work like the following:

    x, err := *p
Where err is nil unless p is nil. And for array indexing:

    x, err := a[n]
The runtime could do its bounds check and return (zero, IndexOutOfBoundsError) if the check fails, where zero is the zero-value for the type. It seems to me that these solutions are perfectly workable except for the massive code-size/verbosity explosion they would induce.

In such cases, the code should effectively prove that p is not nil and n is within bounds before performing the risky operations. Maybe a good plan is to always validate input first so that you can write expression-oriented code that only fails in the case of programmer error.

A situation from my experience was a recursive transformation where an intermediate call had no good way to deal with an error except pass it along to its caller--so I used a panic within the package for that. In hindsight, I think a better solution may have been to validate the input in an earlier pass so that the recursive transformation should always succeed.

So, in cases where the program can validate inputs first, it should do so and then be free to use compositional code that panics when the validation was broken. In cases where validation cannot remove error conditions, error-returns should be used.

Reserving panic for programmer-error, as luriel recommends in his reply, seems like a good maxim. I think I'll try to use that from now on.

comment 14y ago · link · parent

On the topic of when to use error-returns vs. when to use panic:

I struggled with this aspect of Go coding too and what I decided was that, in order to choose your approach to errors, you should think about how important it is that your function can be composed into an expression:

    x := foo(a) + bar(b)
vs.

    c, err := foo(a)
    if err != nil {
        ...
    }
    d, err := bar(b)
    if err != nil {
        ...
    }
    x := c + d
It's a trade-off. By using "panic", you enable more concise and compositional code. By using error-returns, you are being more explicit and making it easier for the caller to handle errors at the call-site.

Usually, functions that can fail are not the kind you desperately want to use in expressions anyway. So error-returns are more common. But there are many situations where errors can happen and where composition is a big win. In those cases, you reach for "panic".

If you look at some of the built-ins that can panic--I'm thinking of array-indexing and division and regexp.MustCompile(), for example--you notice that these would become very cumbersome if they used error-returns instead.

There's also the issue of initialization. That's the justification given in the case of regexp.MustCompile(). An initializer must be a single expression.

The words "panic" and "error" probably lead people to think that you should make the decision based on severity but I don't think that's right.

(That's just my take on it. I'm no Go expert so there are likely better ways to think about it.)

comment 14y ago · link · parent

I've been thinking about block implementation off and on for a while (hobbyist language designer here) and I'd like to try implementing them so that they are never values in the language semantics.

That way, a class of errors becomes impossible; namely, those errors that involve returning from a block whose method has already returned. I would have closures in the language but they would be just like Scheme closures: they would be independent of their creation context except for lexical bindings. I would compile blocks right into the method in which they appear.

Unfortunately, I don't have experience with any language that uses blocks. I'm quite familiar with closures but not blocks. I'm wondering if any Ruby or Smalltalk (or ...) programmer can give some reasons why blocks ought to be values.

Also, (referring to the post) does anyone know why rb_block_t was not embedded in rb_control_frame_t? That's the usual idiom in C and I can't think of a reason not to use it.

comment 14y ago · link · parent

See also: http://lwn.net/Articles/336255/

(A discussion of Linux data structures, including lists).

comment 14y ago · link · parent

Maybe use \033[L (ANSI for insert-line).

Edit: If I understand what you're doing, then maybe you can use this:

    tput ind; tput home; tput il1; echo -n "header"; tput el; tput cup $LINES 0
Use "man terminfo" to lookup things like "il1" and use "infocmp" to see what they translate to in your terminal.

comment 14y ago · link · parent

I just want to add a link for people interested in this discussion.

(Dynamic Languages are Static Languages by Robert Harper): http://existentialtype.wordpress.com/2011/03/19/dynamic-lang...

With HN discussion here: http://news.ycombinator.com/item?id=2346590

comment 14y ago · link · parent

Excellent points. I'm doing a lot of code reading myself these days so it's nice to be reminded of some of the risks. :)

comment 14y ago · link · parent

To attach behaviour to data in a functional language, you typically use first-class functions. Your draw function would look for a function in each drawable object and call it.

To your second question: find some great open source projects and read their code.

comment 14y ago · link · parent

data structure != type

comment 14y ago · link · parent

It seems to me that there's a latent virtual machine in this design. You are breaking code into basic blocks and handling control state in a first class way, so there need to be abstractions for all that, and those abstractions define a virtual machine.

I think that what you describe can work. However, it's not something I can see myself using because I find source-to-source compilation too inflexible and simply don't use it. Such a technique remains as an optimization that I will probably never get to.

comment 14y ago · link · parent

> More research is needed!

Agreed. And I'm looking forward to more posts on Outlet! I have a project that's similar in that it's a Lisp dialect designed to match my own tastes and to eventually run on a variety of platforms. So far, I've had variants of it running on JavaScript and Go. It's in a rough state at the moment but you can see it here: https://github.com/ebb/lumgua and another, rather different incarnation here: http://norstrulde.org/ilge10/ (with some more description here: http://norstrulde.org/ilge10/about.html)

comment 14y ago · link · parent

> As described yes, but you can extract the duplicate bodies in a function.

However, if we do that globally, we're back where we started, right? I mean, the allocation rate of continuation closures will be on the same level as standard CPS.

> Another way if you're willing to take a 2x code explosion hit is to compile each function twice: ...

The idea about compiling functions twice and using a dynamic switch on function entry seems to presume that it can be determined at function call whether a continuation will be captured somewhere within the call and I don't see how you'd do that.

Alternatively, you could introduce a static analysis that identifies functions that provably are not capable of continuation capture and compile only those in direct style. I suppose you could even do the analysis on an expression-level. Of course, Lisp dialects are not particularly amenable to static analysis so it may be hard to get much of a benefit in this way.

However, even if you deal with the code-size issues, I think you are left with a technique for optimizing code for a language that must support continuation capture but you are not left with code that is easy to debug. Every function or block that is compiled in direct style will be impossible to step through or dynamically interrupt.

All criticism aside, thanks for posting the idea! I had never seen a technique like that before.

comment 14y ago · link · parent

Personally, I like the VM technique over compilation to JS source. With a VM, you can track the continuation by simple stack operations rather than furiously allocating JS closures. Think about the effect in memory: when you do a return in a VM, you just pop some stuff off the stack(s) and there is no closure left hanging around for the GC to collect.

The Dybvig "Three implementations of scheme" paper presents a really nice VM and Norvig's PAIP book presents a nice simple compiler for Scheme. Those are the two main sources that I've used for my simple compiler.

Edit: Also...

> I lose all the benefits of JIT-ed Javascript if I run it in a VM.

But if you are using CPS, then your JS functions are going to be really small and the JIT won't have much to work with, right? It's not clear to me that the JIT will be more effective working on CPS JS given that you want to have fine-grained continuations for debugging.

comment 14y ago · link · parent

Won't that lead to a code-size explosion due to the duplication of continuation bodies?

comment 14y ago · link · parent

Yes, I was thinking that too. I like simplicity and I like complexity.

I was also reminded of an old a comment from Guy Steele: http://www.youtube.com/watch?v=4LG-RtcSYUQ&t=1h21m11s

comment 14y ago · link · parent

That's interesting. Sorry for not getting it right away. It's making more sense on second reading. :)

Now I'm curious how you'd encode subroutine calls. Your example was completely inlined but the call-sequence will be critical in determining how compact the code ends up.

Also, were you thinking of using a cross-compiler and keeping the dictionary out of the DCPU-16s memory? Let me know if you create a public repo. I'd be interested to see what you come up with!

comment 14y ago · link · parent

My first try would probably be to use SP for one stack and some other fixed register for the other stack. Also, traditional Forth interpreters don't use code like you showed. I think the main benefit of using Forth (unless you just happen to love RPN) is the compactness of the interpreted code. If you're not going to use an interpreter, then I'm not sure if Forth is really a win.

Edit: Just to clarify about the interpreter point, I'd expect something like "1 2 + >r" to be represented at run time as four words in memory and there'd be an interpreter, written in machine code, reading code word sequences and jumping to small bits of machine code to either do a built-in function or push the call stack.

comment 14y ago · link · parent

Pico Lisp might be a good starting point. Its interpreter for x86-64 machines is written using a simplified custom assembler and already uses a reduced number of registers.

comment 14y ago · link · parent

I don't know about "most people" but I think a machine like this DCPU-16 is better than learning Python or Ruby. Those languages are huge and full of complexity. With a 16-bit machine with a tiny instruction set, the student actually has a chance of getting the feeling, 'I know everything there is to know about this system'. And that connects to a piece of wisdom I love from Design Principles Behind Smalltalk: "If a system is to serve the creative spirit, it must be entirely comprehensible to a single individual".

And there's a certain concreteness to such a machine. The mental model has no vagueness at all. You could imagine building a physical copy of it and playing the role of CPU--adding small numbers, moving data between registers and memory, etc. I've played with this idea myself before of using an invented 16-bit machine as a teaching device.

Maybe it's just a case of personal differences, but as a starting programmer, I would have been extremely excited about a simple programmable thing that I can fully understand and use to do things within a game world. Python is cool too but it's overwhelming. There are learn-Python books that are thicker than most of my university textbooks.

comment 14y ago · link · parent

Typical solution is to use an interpreter (turning data into code). How often is it necessary to run arbitrary machine code on demand?

comment 14y ago · link · parent

There's also the Woz method of thinking about the problem so intently that you can simulate the whole system in your head without even looking at any code. Being unable to write your program bug-free would be like not being able to recognize your mother.

comment 14y ago · link · parent

I won't get into the interface-crossing issue except to say that exceptions to the convention do exist. For example:

http://golang.org/pkg/regexp/#MustCompile

comment 14y ago · link · parent

Go doesn't lack exceptions. It just uses some different names (throw -> panic, catch -> recover) and uses a different way to write the code that catches them.

http://golang.org/doc/go_spec.html#Handling_panics

Edit: Also, here's an interesting pattern to illustrate that Go's panics are a little different.

    func parse(s string, config *Config) (x Thing, err error) {
        defer config.RecoveryPlan(&x, &err)
        x, err = doParse(s)
    }
It's contrived, but you can see that the "RecoveryPlan" can choose to ignore panics or recover from them and it can also affect the return value of the "parse" call by assigning to its parameters and recovering from the panic.

comment 14y ago · link · parent

The error type is an interface. You can return values that contain contextual information as long as the error value you return has an Error() method returning a string.

    type ParseError struct {
        line int
    }

    func (e ParseError) Error() string {
        return "Parse error at line: " + fmt.Sprint(e.line)
    }
Note: The current release may vary slightly on the details. I'm using a pre-release build. But older versions are similar.

comment 14y ago · link · parent

Have a look at the "gob" package for serializer and deserializer support for Go types.

As for the syntax-related points, Go offers quite a bit. There's the goyacc tool, the scanner package, the template package (think quasiquote), and a bunch of packages for processing Go code: go/ast, go/scanner, go/parser, go/printer, go/build, go/doc, etc.

For math-oriented numbers, there's the "big" package. Many languages make such numerics much more convenient but you can get pretty far with little effort using just the "big" package.

1234