149 karma · joined Nov 6, 2009 (17y ago) · 117 submissions
eric.bergstrome@gmail.com
comment 14y ago · link · parent
Edit: Also, as I think about it, one could maybe argue that closures are to expressions as blocks are to statements. In which case, it seems that blocks should never be bound to values but things that invoke blocks should only be able to do so as in the Ruby 'yield' where the block is implicit. You could then avoid the whole escaping problem.
Edit: And further, a thing which invokes a block should maybe belong to yet another category from closures and blocks? In a sense, such a thing is analogous to:
for (...)
or if (...)
In other words, such a thing is half-a-statement. You have to append a block to make a whole statement. :)comment 14y ago · link · parent
While I'm thinking about it... I wonder about the choice to overload/reuse the keyword 'return' in the blocks proposal. Any thought on using something else to emphasize the distinction in semantics?
Edit: Nevermind. That would break the Tennent Correspondence Principle wouldn't it? Bad idea.
comment 14y ago · link · parent
mtime: function () {
return reset {
var mtime = shift (succeed) {
this.withFile ({ |f|
var mtime = this.mtimeFor (f);
if (mtime < new Date () - 1000) {
return "too old";
}
return succeed (mtime);
});
};
sys.print (mtime);
return "young enough";
};
},
The succeed function is a first class, indefinite-extent function equivalent to: function (mtime) {
sys.print (mtime);
return "young enough";
}
It's the computation within the reset block that comes after the shift form is evaluated.Calling it after returning from the method would not raise an exception.
Edit: Keep blocks with 'this' inheritance (I had originally used a standard closure).
comment 14y ago · link · parent
1. Use loop instead of dotimes so you can make the index range over 1-100 instead of 0-99.
2. Factor out the string calculation so you only need one print statement.
3. Maybe use zerop.
4. Don't write ")(". Use a space in between.
Example:
(loop for n from 1 to 100
do (format t "~a~%"
(cond
((and (zerop (mod n 3))
(zerop (mod n 5)))
"FizzBuzz")
((zerop (mod n 3)) "Fizz")
((zerop (mod n 5)) "Buzz")
(t (format nil "~a" n)))))comment 14y ago · link · parent
Looking at the C version, I wondered if it could be done without temporaries curr and prev. My no-temporaries version is not really any nicer, though it does shave off a few lines. :P
void pascal(int n, int *buf)
{
for (int i = 0; i < n; i++) {
buf[i] = 1;
for (int j = i - 1; j > 0; j--)
buf[j] += buf[j - 1];
}
}comment 14y ago · link · parent
pascal 1 = [1]
pascal i = zipWith (+) ([0] ++ pascal (i - 1)) (pascal (i - 1) ++ [0])
I'm not answering your question but just wanted to pique your interest in this because you were asking about language choice and had mentioned that your solution took 50 lines.The above solution expresses the recursive solution as the sum of two earlier rows after appending some zeros. There is very little room for errors to hide and it provides you with a kind of 'definitional' starting point to begin optimizing if you want.
comment 14y ago · link · parent
I also found it surprising that he disliked Dijkstra's display idea since I've used a variant of that to great effect.
Anyway, there's a lot of fun reading in there so thanks for the link! Here's a discussion on Lambda the Ultimate: http://lambda-the-ultimate.org/node/1773
comment 15y ago · link · parent
Doesn't Dart's use of optional typing mean that it really behaves as a statically-typed language in some contexts? The Go language sort of has this via interface types. Consider the following:
type Foo struct { a, b int }
func Bar(x interface{}) Foo {
if f, ok := x.(Foo); ok {
return f // x is a Foo at runtime so return it
}
return Foo{0, 1}
}
There is no need for the Foo type to have a null value. Go does have general zero-values for all types but that's somewhat different from null and not the only solution either. I think a Haskell-like model (neither null nor zero-value) could also work.comment 15y ago · link · parent
Feature request: In text mode, assign <enter> to move the cursor down a line and to the column that text entry began.
Here's my prototype: http://norstrulde.org/tty/tty.html
comment 15y ago · link · parent
comment 15y ago · link · parent
comment 15y ago · link · parent
See http://golang.org/doc/effective_go.html#interfaces_and_types and http://golang.org/doc/effective_go.html#embedding.
comment 16y ago · link · parent
comment 16y ago · link · parent
If they want to protect obsolete business models from technology, I would suggest the following: reduce the privacy and freedom of the entire public by spending lots of public money on big brother programs.
The article gave me the uneasy feeling that they are trying to use the first problem to justify the second solution.
comment 16y ago · link · parent
113.
Tonika: Own your social ties(5ttt.org ↗)
2 points · by ericbb · 16y ago · 1 comment
comment 16y ago · link · parent
Equal temperament uses frequencies that are scaled by powers of the twelfth root of 2. Moving up one semitone is the same as multiplying the frequency by 2^(1/12). If you look at this table
http://en.wikipedia.org/wiki/Equal_temperament#Comparison_to...
you can see how the resulting values approximate certain ratios. Ratios matter because two tones that are related by a simple ratio will tend to have greater harmonic relationship and be more 'consonant'.
Other tunings emphasize different ratios and give up the equal spacing of notes -- equal spacing when plotted by frequency on a logarithmic scale.
comment 17y ago · link · parent
Say that closures lower the syntactic overhead of accessing the same flexibility he normally turns to objects for.
So if he uses closures he will effectively use objects in more situations simply because it becomes easier and this will increase the flexibility of his code.