Arc Forumnew | comments | leaders | submit | coconutrandom's commentslogin
1 point by coconutrandom 5735 days ago | link | parent | on: Atstring problem

I tried for half a second, but dropped it in favor of string substitution.

-----

4 points by coconutrandom 5736 days ago | link | parent | on: Arc 3.1 (works on latest MzScheme)

Oh wow!! I've been working on a small blog/forum in arc, and this new version reduced my local requests from ~140ms to ~60ms.

Thank you all very much for your work on this.

-----

1 point by coconutrandom 5752 days ago | link | parent | on: For a more... civilized age

HAHA! I finally got that joke! That's me right now!!

-----

1 point by coconutrandom 5760 days ago | link | parent | on: How to upload files?

ok, that explains that. thank you

-----


Any thoughts or suggestions?

-----

2 points by fallintothis 5766 days ago | link

The 'li function could be simplified. html.arc has the facilities to define tags; coupled with 'tostring, we can capture the output, giving something like:

  (attribute li class opstring)
  (attribute li id    opstring)
  
  (def li items
    (tostring
      (each i items
        (if (isa i 'table)
            (tag (li class i!class id i!id) (pr i!body))
            (tag li (pr i))))))
This also uses a rest parameter so that 'li can take any number of arguments and collect them up into a list:

  arc> (li (obj body "hi" id "brown") (obj body "world" class "green") "foo")
  "<li id=\"brown\">hi</li><li class=\"green\">world</li><li>foo</li>"
Though it doesn't quite replicate the use of 'string you had originally, e.g.,

  arc> (li ''(a b c))        ; the one defined above
  "<li>(quote (a b c))</li>"
  arc> (li (list ''(a b c))) ; yours
  "<li>quoteabc</li>"
You note that 'gentag prints all over the place. I'm sure (because of the game you built) you notice that Arc uses printing in its html-generation tools. So if you wanted to use this 'li function inside, say, a 'defop, you probably don't want to wrap it in the 'tostring -- instead, let it print so that you don't have to make the call to 'pr yourself.

-----

1 point by coconutrandom 5761 days ago | link

Thanks for the info, didn't know the 'tostring did that!

The reason I didn't want it to pr at the moment was the output from this or other functions could be assembled to make a html template system.

-----

2 points by conanite 5766 days ago | link

I don't see how to inject request-scoped variables - it seems you can only call functions in the global namespace. In other words, how would you render

  <span>hello, @(current-user)</span>
for multiple concurrent users?

A separate, and totally subjective, observation: one advantage of having prs all over the place is that output gets sent directly to the client, rather than getting buffered on the server (caveat: depending on how the stream is implemented I suppose). Writing to a string and then printing that string might be more resource-intensive; only an issue for high-volume sites though. The big win I've had with prs all over the place is that when something goes wrong (and arc isn't always very helpful when something goes wrong), you can "view source" in your browser and see where output stopped, and then hopefully make a guess as to where the error is in your code.

-----

1 point by coconutrandom 5761 days ago | link

True and true, current-user would have to be passed to a function to do something with it.

Interesting about buffering the output. Lots to learn still.

-----

1 point by coconutrandom 5771 days ago | link | parent | on: A noob's guide to web apps in arc

Added and fixed. :)

hand->face for not seeing the typo

-----

2 points by coconutrandom 5773 days ago | link | parent | on: A noob's guide to web apps in arc

Good point.

Feel free to use user:pass as a login. I considered using cookies, but personal and global high scores are next the list and I was heavily referencing blog.arc, besides, you only have to login once.

-----

2 points by coconutrandom 5774 days ago | link | parent | on: A noob's guide to web apps in arc

I wrote this because as someone who enjoys programming, lisp is/was a bit of a steep hill to climb, and hopefully this could help pave the way for others. I'll post this on HN in a bit, but just wanted some feed back. Please tell me anything I missed or your thoughts in general.

check it live: http://coconutrandom.com:8080/guess

side note: it's took me 20 days at 1-3 hours a day to write these 60something lines of code. And the majority was written in the last two days.

-----

1 point by coconutrandom 5773 days ago | link

[edit] the answer is from 0 to 99 inclusive

-----


:D thank you! I didn't know both end up with tail recursion and the 'nil was also bugging me

I've already installed Arc on my webhost. Now I'm picking my way through the webserver and am translating this to a web app.

-----

1 point by shader 5790 days ago | link

The nil is the return value of the function. Since the last thing you did was an assignment, is 'nil. It only shows up like that on the repl, which prints both stdout and return values. It is true that printing a newline first would make it show up in the next line, but it doesn't really matter if you're making it into a web service since the nil won't be printed.

-----


Ahh... concise and readable. Thank you!

[edit] I just found that the "o" makes the arguments optional. That explained a lot.

-----

More