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 14y ago · link · parent

Here's a question about blocks: should they even have return values? I was wondering about that because (1) they are supposed to have an equivalence with a code sequence and code sequences don't have values and (2) one awkward difference between blocks and closures is that a closure can return a value early whereas a block can only (as I understand) return the last value of its body.

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

Thanks for the links. It's neat to see such things being considered. My feeling is that such complicated language devices are out of place in JavaScript but it was fun to run the experiment.

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

Alternate formulation with hypothetical shift/reset (delimited continuation support) and blocks that return the same way functions do:

    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

Hehe. That's quite a monster. I'll try to be a bit more helpful.

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

Surely, the lispiest way is to write an interpreter! Write a function fizzbuzz-eval so that the following is a solution (left as an exercise). ;)

    (fizzbuzz-eval
     100
     '(((3 5) (print "FizzBuzz"))
       ((3)   (print "Fizz"))
       ((5)   (print "Buzz"))
       (()    print-number)))

comment 14y ago · link · parent

I like both of those solutions. The Haskell solution is almost the same as what I had come up with but I wasn't familiar with iterate, which makes it even nicer. So thanks for that.

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

This kind of problem has really short solutions when you have access to collection-at-a-time operations. For example, in Haskell:

    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 just skimmed through it and there's a really controversial claim in there that the functional paradigm was a bad idea!

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 14y ago · link · parent

For language enthusiasts with hobby compilers, the question does not have to be a hypothetical. :)

comment 15y ago · link · parent

I haven't read much at all about Dart yet so forgive me if I'm missing something but it seems to me that dynamic-typing capabilities do not rule out absence-of-null.

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

Sounds like the Ubiquitous Language idea from Domain Driven Design is a closer analogue. I haven't read Christopher Alexander's book so I'm just going on the article's summary.

http://domaindrivendesign.org/node/132

comment 15y ago · link · parent

Cool! This is something I wanted to have and had started making for myself. Mine is much less useful than asciiflow but the thing I like most about it is that it allows writing and drawing more in the way I use my notebook. It's easy to write little blocks of text that aren't aligned along the left margin.

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

Isn't "New Jersey Lisp" a contradiction in terms?

comment 15y ago · link · parent

I actually liked the earlier article better. But I think it's good to see the paths that have been taken to get to where we are today. Just because you have seen what the original LISP was like doesn't mean you are forever doomed to believe it's the only way things can be! After you write your Ur-Lisp, check out The Art of the Interpreter: http://repository.readscheme.org/ftp/papers/ai-lab-pubs/AIM-....

comment 15y ago · link · parent

Go does. See my other comment in this thread: http://news.ycombinator.net/item?id=2058963.

comment 15y ago · link · parent

Seems a lot like Go (http://golang.org).

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

http://norstrulde.org/tty/tty.html An ASCII-art, note-taking, {box,line}-drawing thing. Was the first thing I made with Javascript. Drag-n-drop to draw. Type to insert text. Edit: I think Safari is the only browser it kind of works in.

comment 16y ago · link · parent

What's so bad about C? It's not very pretty but the following was easy enough to write and worked first try.

http://pastebin.com/QBAgzWWJ

Pipe the result through "sort -u" if you don't want dups.

comment 16y ago · link · parent

They want to protect the public from unsafe false copies? I can suggest this for software: educate the public on the use of simple cryptographic tools. The public needs to know how to check for themselves that their torrented copy is an authentic copy.

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

A good read on this topic: John Carmack's .plan entry from 14 Oct 1998. He writes about replay as a development tool, how it's necessary to record time, and how journaling inputs "turns a realtime application into a batch process".

comment 16y ago · link · parent

Having skimmed the PicoLisp interpreter a long time ago, I remember it being like Emacs Lisp in that common performance-critical functions like mapcar were implemented in C. It seems like a very pragmatic way to get the performance you need without getting into byte codes or machine language. And since you are still interpreting the s-exprs directly, debugging and introspection remain easy.

comment 16y ago · link · parent

Of particular note to some hackers: it is written in Go.

113.

Tonika: Own your social ties(5ttt.org ↗)

2 points · by ericbb · 16y ago · 1 comment

comment 16y ago · link · parent

If you are mathematically inclined, this might help. It's how I, as a non-musician, came to understand tuning a little.

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 16y ago · link · parent

From the article:

  Edit 2: One quick question for the "Anything can be cracked
  right away." crowd. Where do I get my cracked copy of World
  of Warcraft that can play the real game (not some cobbled
  together emulation server) without paying. Answer: You can't.

comment 16y ago · link · parent

Me too. This was my primary resource while learning the language and I highly recommend it.

comment 17y ago · link · parent

Closures are different from objects in only a couple of ways: (1) the creation protocol is extremely concise (lambda) (2) the access interface is the function call

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.

1234