Arc Forumnew | comments | leaders | submit | thaddeus's commentslogin
3 points by thaddeus 5654 days ago | link | parent | on: First Arc pages at pittshuttle.info

Looks good. I am sure the students will appreciate not having pdfs.

I would try something like jqTouch for the client side phone UI, targeting the iPhones/Androids out there - which is probably 90% of the students these days :)

http://www.jqtouch.com/

I have yet to try it, but I look forward to giving it a whirl (with Arc as the back end).

-----

1 point by evanrmurphy 5650 days ago | link

Thank you, thaddeus! I'm glad to know about jQTouch and will let you know if I give it a whirl before you do. :)

-----

2 points by thaddeus 5654 days ago | link | parent | on: popnth

  (= ls (list 1 2 3 4))

  (defset nthcdr (n xs)
    (w/uniq g
      (list (list g xs)
            `(nthcdr ,n ,g)
            `(fn (val) (scdr ,g val)))))

  arc> (pop (nthcdr 1 ls))
  2

  arc> ls
  (1 3 4)

-----

3 points by shader 5654 days ago | link

Actually, I don't think that's a complete solution. It sets the cdr of ls to be the nthcdr of ls. What you want is to set the nthcdr of ls to the nthcdr+1 of ls.

Ex. with your defset:

  arc> (= ls '(1 2 3 4 5))
  (1 2 3 4 5)
  arc> (pop (nthcdr 2 ls))
  3
  arc> ls
  (1 4 5)
As you can see, it effectively removed both the 2nd and 3rd elements, instead of just the 3rd.

A better defset would be:

  (defset nthcdr (n xs)
    (w/uniq g
      (list (list g xs)
            `(nthcdr ,n ,g)
            `(fn (val) (scdr (nthcdr (- ,n 1) ,g) val)))))
Ex:

  arc> (= a '(1 2 3 4 5))
  (1 2 3 4 5)
  arc> (pop (nthcdr 2 a))
  3
  arc> a
  (1 2 4 5)
With this version, only the nthcdr itself is popped.

-----

1 point by thaddeus 5654 days ago | link

yup, I should have seen that :)

-----

2 points by shader 5654 days ago | link

It's still not perfect. Since it's based on scdr, if you do (pop (nthcdr 0 a)), it doesn't pop the first element, which it probably should.

Oh well. I can't really imagine anyone would actually do that, given that you could use (pop a) instead ;)

-----

1 point by evanrmurphy 5654 days ago | link

Wow, looking back it was awfully dense of me to have your clear explanation about needing to define a setter and then coming over here to post some hack using join. Sorry for that.

Even though my popnth function works, it's a worse solution because by ignoring setforms it only works for the specific case of pop rather than the whole family of destructive functions. Is this accurate?

I'm a good deal more comfortable with the setter concept after your and thaddeus' examples. Thanks to both of you for your patience with a newb. I've been super impressed with this forum so far: the community is small but outstanding.

-----

1 point by shader 5653 days ago | link

Yep. By defining popnth, you get a single function that performs a specific task. But if you define a setform, now any function that wants to operate on a "place" can do so.

In theory, you can now do things like

  (= (nthcdr 3 lst) '(a s d f))
and set the 3rd cdr of lst to (a s d f)

-----

1 point by evanrmurphy 5654 days ago | link

That's probably more natural and efficient than my solution.

-----


Thank you both!

With (run-job) I was iterating through items and displaying progress to stderr using 'prne'.

  (def prne args (w/stdout (stderr) (apply prn args)))

  example...
  (def run-job ()
     (each item (keys items)
        (process items.item)
        (prne item)))
I suppose I should have just removed the progress, but wrapping run-job in 'w/stdout' as suggested worked perfectly! (+ I plan change it to write to a log file instead).

... and thanks for the detailed explanation.

-----


Yup + manage https well (not a login, just an https page).

-----

2 points by aw 5666 days ago | link

By "manage", do you mean to download a page? Has curl been giving you trouble downloading https files?

For downloading http or https files or pages, both curl and wget work well, and I'm surprised to hear that curl would be giving you trouble. What exactly is the problem that you're seeing?

For looking at a downloaded HTML page and looking for links that match a particular pattern, I often find that regex's work well.

-----

1 point by thaddeus 5666 days ago | link

I've tried a dozen options in curl... but it couldn't get it working... curl: (35) error:140773F2:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert unexpected message

however wget worked for me!!! and I should be able to write code to follow the links from there. thanks.

-----

1 point by thaddeus 5666 days ago | link | parent | on: Re: How to upload files?

I was planning on giving uploadify a whirl, but have yet to find time.

http://www.uploadify.com/what-is-it/

-----

1 point by evanrmurphy 5666 days ago | link

That looks interesting, thanks.

  > It requires Flash and any backend development language.
I'd certainly prefer an implementation that didn't depend on Flash, but this may be a "beggars can't be choosers" type of situation. :)

-----

2 points by thaddeus 5666 days ago | link

I believe this one does not use flash...

http://valums.com/ajax-upload/

-----

2 points by shader 5666 days ago | link

I'm not sure that either of those are what he's looking for. Both seem to be different ways of displaying the upload form to the user, but neither seems to change the way that the back end handles the file.

It sounds like he wants a way for arc to receive an uploaded file in an http request, and do something with the data, rather than a way to display an upload form.

-----

1 point by evanrmurphy 5666 days ago | link

Yes, that is correct.

-----


I think you intended to do this:

  (defop shuttle req
    (each r routes* (link r)(nbsp)))
And don't ask me why the following works - it's a brutal hack!

  (= routes* '("10a" "10b" "15a" "20a" "20b" "30a" "30b" "30c" "40a" "59u"))

  (defop shuttle req
    (each r routes* (link r)(nbsp)))

  (def rpage (r)
     (pr r))

  (mac rdefop (rs)
    (eval `'(defop ,(fromstring  rs (read)) req 
	          (rpage ,rs))))

  (each r routes*
    (eval `(rdefop ,r)))

[edit] corrected link as per aw's post.

-----

1 point by thaddeus 5668 days ago | link

Curious if any of the more advanced folks on this board can show how to properly do the above code (such that I can learn from). Or is the above code not so bad after all? Thanks.

-----

1 point by shader 5668 days ago | link

Why do you need the eval in rdefop? What am I missing?

-----

1 point by thaddeus 5668 days ago | link

I am not sure. It didn't work for me when I took it out.

-----

3 points by fallintothis 5667 days ago | link

You don't really need eval in the macro. In the original,

  (each r routes*
    (rdefop r))
macroexpands into

  (each r routes*
    (defop r req (pr "Schedule for " r " goes here")))
without evaluating what r is bound to --- you'll just get an /r handler.

So, using eval makes sure r gets evaluated. But you do this haphazardly between two points:

  (mac rdefop (rs)
    (eval `'(defop ,(fromstring  rs (read)) req
                  (rpage ,rs))))

  (each r routes*
    (eval `(rdefop ,r)))
We only need to eval once.

  (= routes* '(10a 10b 15a 20a 20b 30a 30b 30c 40a 59u))

  (def rpage (r)
    (pr r))

  (mac rdefop (r)
    `(defop ,r req (rpage ',r)))

  (each r routes*
    (eval `(rdefop ,r)))
Thus, instead of doing (defop r), it's kind of like we're doing (defop (eval r)). That is, instead of expanding into

  (defop r req (rpage 'r))
we're expanding into

  (defop 10a req (rpage '10a)) ; when r == '10a
  (defop 10b req (rpage '10b)) ; when r == '10b
  ; etc
We could've done the eval inside the macro, too, but that's often a sign you're doing something wrong --- macros are usually there to not evaluate their arguments. So we should probably use a function.

However, defop itself is a macro, so the first parameter (the op's name) won't be evaluated regardless. We still need eval.

  (= routes* '(10a 10b 15a 20a 20b 30a 30b 30c 40a 59u))

  (def rpage (r)
    (pr r))

  (def rdefop (r)
    (eval `(defop ,r req (rpage ',r))))

  (each r routes*
    (rdefop r))
Since this approach seems to require eval regardless, we should just look for a better solution. aw's works nicely.

Some other nitpicks over your rewrite (hey, you asked!):

1) Unless you need strings for some reason, you can probably default to symbols (they're a bit easier to use).

  ; Instead of

  (= routes* '("10a" "10b" "15a" "20a" "20b" "30a" "30b" "30c" "40a" "59u"))

  ; we could use

  (= routes* '(10a 10b 15a 20a 20b 30a 30b 30c 40a 59u))
2) Proper spacing & indentation saves lives. :)

  ; Instead of

  (defop shuttle req
    (each r routes* (link r)(nbsp)))

  ; why not

  (defop shuttle req
    (each r routes* (link r) (nbsp)))

  ; or even

  (defop shuttle req
    (each r routes*
      (link r)
      (nbsp)))
3) Though using symbols renders this point moot, fromstring is unnecessary to simply (read) from a string, since Arc's definition of read is

  (def read ((o x (stdin)) (o eof nil))
    (if (isa x 'string) (readstring1 x eof) (sread x eof)))
So, instead of

  (fromstring rs (read))
you can use

  (read rs)
If your goal is just to turn a string into a symbol, you should use

  (sym rs)
This is an important distinction. e.g.,

  arc> (sym "abc")
  abc
  arc> (read "abc")
  abc
  arc> (sym "(a b c)")
  |(a b c)|
  arc> (type that)
  sym
  arc> (read "(a b c)")
  (a b c)
  arc> (type that)
  cons

-----

1 point by evanrmurphy 5667 days ago | link

Very instructive. Thank you for doing such a thorough analysis.

',r from your snippet

  (mac rdefop (r)
    `(defop ,r req (rpage ',r)))
was a realization for me. Never thought of quoting a comma'd symbol in a backquoted expression before, but I like knowing it's possible. Do you find yourself doing this much, or is there usually something simpler like aw's solution available to make it unnecessary?

-----

2 points by fallintothis 5667 days ago | link

Happy to help.

Oh, yes, quoted-unquotes are done pretty often.

  $ grep -c "'," {arc,code,html,srv,app,news}.arc
  arc.arc:17
  code.arc:1
  html.arc:6
  srv.arc:9
  app.arc:1
  news.arc:7
For example, the Arc built-in obj is a macro that makes a hash table with automatically-quoted keys.

  arc> (= h (obj a 1 b 2))
  #hash((b . 2) (a . 1))
  arc> (h 'a)
  1
  arc> (h 'b)
  2
It's defined like so:

  (mac obj args
    `(listtab (list ,@(map (fn ((k v))
                             `(list ',k ,v)) ; note we unquote k, then quote it
                                             ; so we're quoting the value of k
                           (pair args)))))
That way, the above (obj a 1 b 2) expands into

  (listtab (list (list 'a 1) (list 'b 2)))

-----

1 point by evanrmurphy 5667 days ago | link

Thanks again.

-----

1 point by thaddeus 5667 days ago | link

dito

-----


Not sure if you can repost your comment/email to Eli, but your reference URL to the arclanguage.org topic was incorrect. Eli wouldn't get to it.

-----

1 point by akkartik 5671 days ago | link

Argh, it replaced the '=' with '=3D'.

Presumably subscribers will see the correct link in their email.

-----

2 points by thaddeus 5671 days ago | link | parent | on: Arc with SQL, NoSQL thoughts/questions

Looking at the CouchDB overview http://couchdb.apache.org/docs/overview.html. Am I reading this right? CouchDB IS ACID compliant?. Thus all the rants stating NoSQL is not ACID are just incorrect? Or is the statement that it contains ACID properties, but not compliant? Quite confusing.

-----

2 points by thaddeus 5671 days ago | link | parent | on: 3D Graphics and Foreign Interfaces

This may be worth the read.

http://www.arcfn.com/2008/05/using-opengl-with-arc.html

http://www.arcfn.com/2008_06_01_archive.html

-----


twice on Mac OSX 10.6.2 MzScheme 4.2.2

twice on Ubuntu Jaunty MzScheme 4.2.2

no errors.

-----

More