149 karma · joined Nov 6, 2009 (17y ago) · 117 submissions
eric.bergstrome@gmail.com
comment 13y ago · link · parent
(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
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
comment 13y ago · link · parent
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
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
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
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
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
(A discussion of Linux data structures, including lists).
comment 14y ago · link · parent
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
(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
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
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
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
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
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
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
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
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
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
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
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.