Arc Forumnew | comments | leaders | submitlogin
3 points by akkartik 5420 days ago | link | parent

Nice! I'd forgotten about deftem, should use it more.

I like ret and mapair. But not how you are overloading between.

And how the heck is param avoiding infinite recursion?

I suspect you can make shuffle+choices shorter by using rand-choice+pull.



2 points by fallintothis 5420 days ago | link

It might be worth noting that ret was unnecessary in this case.

  (mac ret (var val . body)
   `(let ,var ,val ,@body ,var))
   
  (def question (url q a b c d)
    (let id (++ question-id*)
      (ret new (inst 'question
                     'id id 'url (video-url url)
                     'q q 'a a 'b b 'c c 'd d)
        (= (questions* id) new))))
could just be

  (def question (url q a b c d)
    (let id (++ question-id*)
      (= (questions* id)
         (inst 'question
               'id id 'url (video-url url)
               'q q 'a a 'b b 'c c 'd d))))
ret would certainly be useful in general, of course.

-----

3 points by skenney26 5420 days ago | link

I like your rewrite of 'question.

I agree that 'ret would be more useful in other areas than here. In arc.arc 'best, 'summing, 'sum, 'listtab, 'copy, 'inst, 'w/table, 'memtable, and 'evtil all use this idiom of creating a local variable with 'let and then returning it.

-----

1 point by skenney26 5420 days ago | link

Thanks for the feedback. I'll take a look at how rand-choice and pull can improve shuffle and choices.

I use between alot with numbers and would like a similar utility for strings, but I understand its confusing that the arguments to between work exclusively with strings but inclusively with numbers.

param is just mapping over a paired list. Infinite recursion shouldn't be a problem.

-----

2 points by akkartik 5420 days ago | link

There's a call to param inside param's body. Isn't it the same fn? Ah, it's just the tag macro's private language.

between with a string == substring between delimiters. between without a string == pick a random number in a range. Is that right? It's not just about exclusive/inclusive, that's pretty different semantics.

-----

1 point by skenney26 5420 days ago | link

I meant that the return value of the string version doesn't include the delimiters (between "ab" "ef" "abcdef"), while when something like (between 3 7) is called, the return value could also be 3 or 7.

Maybe it would make more sense to modify rand so that it could return numbers in a range if given 2 arguments.

-----