Adlai


3 points by Adlai about 1 year ago | link | parent | top
cached 13 days ago
What if a default specified at lookup overrode the default specified when the table was created?

My Arc knowledge is essentially #f at the moment, but this

  ((hash-table? fn)
   (ar-nill (or (hash-table-get fn (car args) #f)
                (hash-table-get fn hash-table-default #f))))
seems to be the code for looking up a key using the (some-table key) syntax (i.e. putting the table as the "function" in a form). Would it work to have an optional parameter, so that somebody could call (some-table key default) if they wanted to override the default? I'm thinking that this optional parameter would default to #f if unspecified, and would be passed to the first hash-table-get in the above code. This seems to enable overriding of a pre-specified default.

3 points by Adlai about 1 year ago | link
cached about 24 hours ago

2 points by Adlai about 1 year ago | link | parent | top
cached 22 days ago
Should there be a periodical (i.e. once/twice a month) effort to merge together various publishings of the same hack? I think it's important to do that, so that we don't have five differently-named but almost identical versions of a hack floating around after a few people add features. A list of contributers to a hack/library can be kept as commented "meta-data" within the file, and the hack can then be renamed to anarki.hackname.release.

2 points by Adlai about 1 year ago | link
cached 10 days ago

2 points by Adlai about 1 year ago | link | parent | top
cached 10 days ago
I think two is better, because it a) clearly distinguishes it as indentation (rather than just an accidental #\space), and b) it's consistent with the indentation of macros & co.

2 points by Adlai about 1 year ago | link | top
cached 10 days ago
It's a good start -- it works, which always is a plus :)

However, a few comments about your version:

- You use an iterative 'while, rather than the tail-recursive approach that Paul Graham posted. Both end up eventually as tail-recursive code, however, I think that it's better, in this case, to write the tail-recursion directly. The reason for this is that in your version, you have to explicitly "break out" of the loop (by setting 'tries to 1), while in Paul's version, he just doesn't call the next "iteration".

- You should probably use 'prn for the last message -- when I run this, "nil" gets tacked on to the end of the message.

- This is more just a matter of convention, than an actual problem, but your indentation isn't completely standard. Usually, body code for macros is only indented by two spaces. Also, having several tokens on one line can get a bit confusing, and in a form like 'with, I think it helps to organize them. I think the start of your code could be more readable like this:

  (def guess ()
    (with (tries 10
           r (rand 100))
      (while (> tries 1)
        etc)))
As for some derisive best practice about optimization -- "Premature optimization is the root of all evil." (Donald Knuth)

2 points by Adlai about 1 year ago | link | parent | top
cached 3 days ago
Very useful... I'm surprised that it's not the "standard" yet. Nice job!

2 points by Adlai about 1 year ago | link | parent | top
cached 2 days ago
I'm not sure about your related note, but for an example of symbol macros in use:

This example is from Common Lisp's object system, called CLOS. When you want to do some code while accessing specific slots of an object, you can use a 'with-slots form, which lets you name symbols that you'll use to reference specific slots of the object. The 'with-slots form then generates local symbol-macros for each symbol you mentioned, which expand into code to access those slots. An example, taken from PCL [1]:

  (with-slots ((bal balance)) account  ; Here 'balance is the name of the slot, and 'account is the specific object
    (when (< bal *minimum-balance*)    ; *symbol* is a CL convention for global variables
      (decf bal (* bal .01)))))        ; decf is like --
[1] Practical Common Lisp, by Peter Seibel, available online at www.gigamonkeys.com/book/

2 points by Adlai about 1 year ago | link | parent | top
cached about 16 hours ago
The return value should correspond to what was being searched for.

In other words, searching for one character should return an index, while searching for a substring should return a range.

There are thus four operations which would ideally be possible through ("abc" x):

  arc> (= str "hello arc!")
  "hello arc!"
  arc> (str "arc")
  6..8     ; or some other way of representing a range
  arc> (str #\!)
  9
  arc> (str 5)
  #\space
  arc> (str 4..7)   ; same as previous comment
  "o ar"
A way to take advantage of multiple values, if they were available, could be something like this:

  arc> (str #\l)
  2
  3

2 points by Adlai about 1 year ago | link | top
cached about 16 hours ago
Another idea along this line is to enable code like this:

  arc> (let str "Hello world!"
         (= (str "world") "arc")
         str)
  "Hello arc!"