Arc Forumnew | comments | leaders | submit | bOR_'s commentslogin
1 point by bOR_ 6323 days ago | link | parent | on: Using conditions within a withs

Thanks! That might be the first thing I learn from lisp where things work fundamentally different than ruby. This gives some interesting possibilities.

-----

1 point by bOR_ 6324 days ago | link | parent | on: What can't LISP do?

That one requires anarki?

-----

3 points by brucio 6324 days ago | link

It's SBCL, but the point is any serious Lisp will have the facility to do the same thing.

-----

1 point by rntz 6324 days ago | link

That depends on how you define "serious". I doubt there are many Schemes with the ability to write into arbitrary regions of memory.

-----

2 points by brucio 6324 days ago | link

Serious Schemes let you do this, or let you add it without much trouble.

-----

1 point by rntz 6323 days ago | link

Really? Can you list the lisps (common lisps, schemes, whatever) that let you do this kind of stuff? And tell me why the ones that don't aren't "serious", according to you?

-----

6 points by brucio 6323 days ago | link

SBCL, CMUCL, LispWorks, Allegro CL, CLISP, etc. make it easy.

I don't habitually use Scheme, but Rob Warnock used MzScheme for hardware debugging all the time; check google groups for "rob warnock scheme mmap".

Lisp is a general purpose programming language; no less so than C. If you can't do anything C can do with your Lisp, it's time to upgrade your Lisp.

-----

3 points by rntz 6313 days ago | link

So, according to you, Python isn't "general-purpose" and Haskell isn't "serious"? I could list many more languages here, of course, but my point is obvious.

It's useful to be able to do lowlevel bitflipping stuff, that I don't deny; and I am suitably impressed by the number of lisps that have put thought into allowing this. But just because a language lacks such capabilities doesn't mean I'd rather use C, or even Lisp! And often, if I'm really interested in lowlevel stuff, I'm also intimately concerned with things like speed and memory usage that I can't necessarily address even in a highly optimized lisp. For example, all lisps need GCs (what if I want to write a GC? I'd rather not have my GC itself need GC, and I'm not learned enough concerning the implementation of eg. SBCL to, like the writers of T, write a GC in it such that the GC needs no GCing), and any Common Lisp necessarily comes with a huge standard library attached.

-----

4 points by bOR_ 6330 days ago | link | parent | on: Poll: Destructive operations naming

Except that the ruby way isn't consistent. ! is used to warn people that this method is destructive for sure. The lack of ! doesn't imply non-destructiveness.

That bit me before ;) http://www.ruby-forum.com/topic/135076#new

-----

2 points by bOR_ 6335 days ago | link | parent | on: Show and Tell: ballerinc.com

Although just from the website it is a bit hard to see how arc is being used. Perhaps if something interesting during building the site was encountered, this could be shared?

-----

11 points by antiismist 6335 days ago | link

Sure, I can share some things I've learned. The caveat of course is that I am no elite hacker, so some of this is going to be obvious or not really correct...

- macros: In news.arc, they are all over the place. So I tried to code in a similar style, but it turns out that if something can be done via a macro vs being done with a function, then it is more natural for me to use a function. I work a lot with the REPL, and it turns out to be really annoying to change a macro, and then I have to track down all the places that use that macro, and "refresh" them to use the new macro. Especially with macros that call macros that call macros, and I change the macro at the end of the chain. Whereas with a function, I just have to paste in the new function and it takes effect right away.

- news.arc stores posts in a hash table. I started off modeling ballerinc that way. But as time goes on, I am starting to move things over to plain old lists. Basically, working with a hash table pushes me into code that uses side effects to get things done, like using each. Whereas with lists, the code is usually cleaner and shorter.

- repl: using the repl on the running web server is pretty amazing. Already I have pushed changes directly to the live site. For ballerinc restarting the server takes about 10 minutes, so this has been a life saver. I don't worry about "releases" at all anymore - just make the feature, test it, and deploy it.

- the codebase is about 386 LOC. For the past week I've been adding features and doing code cleanup, and the LOC keeps going down.

-----

1 point by skenney26 6335 days ago | link

Any advice related to setting up and running your web server would be highly appreciated. I recently got a hosting account and was stuck trying to figure out how to keep the server running after logging out of ssh. Also, have you had any security concerns while developing your applications?

-----

3 points by antiismist 6335 days ago | link

I use the screen utility. Basically, I always have screen running, and the repl / vim running. With the repl running in screen you can detach via control-a d, and then log off, and the repl keeps on running. Then you ssh back in, and can reattach via screen -dr.

I haven't had any security concerns - I have a couple admin pages but of course one has to be an admin to see them.

-----

2 points by zitterbewegung 6335 days ago | link

How do you parse the rss feeds?

-----

2 points by antiismist 6335 days ago | link

That part is a big hack...I have a ruby script that generates an s-expr of the feed, and work from that:

       (each i (read (tostring (system (string "ruby bench.rb " r!url))))
           (add-post (alref i 'title) (alref i 'link) r!league))

-----

2 points by zitterbewegung 6334 days ago | link

There is a function (xml->xexpr) in PLT scheme which could also generate an s-expr of the rss feed.

-----

1 point by antiismist 6334 days ago | link

I had trouble figuring it out ...

If you had a URL for an RSS feed, how would you get an s-expr containing all the links and titles in the items?

-----

2 points by bOR_ 6344 days ago | link | parent | on: Objects in Arc

From another beginner ;). Isnt this what templates are for? Here is a template I am using:

  ; Template of a creature
  (deftem creature 
   symbol #\@
   dir '(1 1) 
   pos '(0 0)

   ;memory bits
   stm (n-of 7 nil)
   oltm (table) ; ltm - the objects associated with a
   altm (table) ; ltm - the actions associated with a
   cltm (table) ; ltm - the emotions associations with a
   ltmsize 25

   s2ltm 3

   ;list of behaviours/ actions
   action (list act_bite)

   ; observations:
   fov 110  ; fov not being exactl fov, but half-fov
   range 7
   hunger 0
   )
and now I can just call an instance of this template, including its default values. I basically use that as my objects.

  (= craa (inst 'creature))

-----

2 points by EliAndrewC 6343 days ago | link

Does this give you any kind of "this" object in your object methods? That's a large part of what I'm looking for, since that lets me say "(p!until 30)" in my example, or something like "(craa!act_bite)" in your example.

-----


Might be an idea to start working on this (even I can do this ;). I was browsing through my bookmarks, and found an old one leading to the ruby version of PLEAC, which had been of great help when I started with ruby.

-----

1 point by jmatt 6370 days ago | link

I think this would be a fun and useful project for the community and any newcomers. There is already a scheme dialect in the top 5 languages, Guile.

I don't know the best way to begin. Maybe add it to Anarki with a link to the perl code for now. I think it's a huge undertaking and could progress pretty slowly if PG doesn't actively develop arc. But at the same rate it could be really useful to find arc's weaknesses.

-----

2 points by bOR_ 6374 days ago | link | parent | on: Arc Programming Assignment

Ah.. I remember reading about the reasoning behind that (Round-to-even)

from: http://en.wikipedia.org/wiki/Rounding

  Although it is customary to round the number 4.5 up to 5, 
  in fact 4.5 is no nearer to 5 than it is to 4 (it is 0.5 
  away from both). When dealing with large sets of 
  scientific or statistical data, where trends are 
  important, traditional rounding on average biases the data
  upwards slightly. Over a large set of data, or when many 
  subsequent rounding operations are performed as in digital
  signal processing, the round-to-even rule tends to reduce 
  the total rounding error, with (on average) an equal 
  portion of numbers rounding up as rounding down. This 
  generally reduces upwards skewing of the result.

-----

1 point by bOR_ 6375 days ago | link | parent | on: (delist somelist)

Different problem, similar question.

rand-choice returns one of its arguments. Can it also pick one of the arguments in a list?

  (rand-choice (list 1 2 3)) 
gives (as per expected)

  (1 2 3)
and to pick a random value of a list I currently use

  (let mylist (list 1 2 3)
     (mylist (rand(len mylist))))
Scanned through arcfn.com, but didn't spot anything that turns a list into a number of arguments, so that it can be fed to rand-choice

  (rand-choice (delist mylist))

-----

2 points by almkglor 6374 days ago | link

'apply

  (apply rand-choice (list 1 2 3))

-----

2 points by bOR_ 6374 days ago | link

Had tried apply, but that doesn't work in arc2. I get a

  "Function call on inappropriate object #3(tagged mac #<procedure>) (1 2 3)"
Might be inevitable for me to move over towards anarki, if it works there. :P

-----

3 points by absz 6374 days ago | link

Actually, in looking over the functions again, it turns out that there is already a function that does what you want: random-elt. That should do what you need it to do.

As for your problem (and no, it doesn't work on Anarki[1]), the problem is that rand-choice is a macro, not a function, and apply only works on functions. The only solution is a terrible hack:

  (def mapply (macro . parms)
    " Applies the macro `macro' to `parms', which are not quoted.
      See also [[mac]] [[apply]] "
    (eval:apply (rep macro) (join (butlast parms) (last parms))))
But don't use that!

[1]: But you should use Anarki anyway :)

-----

2 points by bOR_ 6374 days ago | link

Thanks for the reminder not to apply on macro's, and for finding random-elt. I need to learn how to read ;).

random-elt does exactly what I want.

(btw.. small consistency issue in the syntax here?) rand-choice random-elt

-----

1 point by absz 6374 days ago | link

To further clarify, if you've programmed in Ruby or Python: (apply func ... arglist) is equivalent to func(..., * arglist) in those languages.

-----

2 points by bOR_ 6375 days ago | link | parent | on: arc2c update

Seriously lack the programming-fu to help you there (unfortunately)(just learning how to use macros), but following with interest what you're doing!

-----

2 points by bOR_ 6377 days ago | link | parent | on: Proposal: "." Syntax Sugar

Is there a list of the syntax sugar we have so far?

I remember being told about table!key being equivalent to (table key), and : is used to string functions together (although I keep forgetting it works from inside out).

I'm not sure what . offers, except that you can do *(3 . + . 5) with it. The example of foo.bar being equal to (foo bar) isn't helping much either ;)

-----

2 points by absz 6377 days ago | link

See http://arclanguage.org/item?id=4012 .

Note that you can also use : to compose multiple functions.

The Anarki also has, if you include "ssyntaxes.arc":

11. x..y, which is the same as (range x y), and x..y..z, which is the same as (range x y z) (a range from x to y with step size z).

12. f//g, which is the same as (orf f g); this returns a function where ((orf f g) x y ...) is equivalent to (or (f x y ...) (g x y ...)). This can be used with as many functions as you want.

13. f&&g, which is like f//g but uses andf instead of orf, so the function is equivalent to (and (f x y ...) ...).

14. typ?, which returns the function (fn (x) (isa x 'typ)).

15. User-definable ssyntax, so you can add your own!

Also, note that ssyntax only works with variables and integers, not with literal lists or function calls.

And your example of using . for infix is actually a holdover from mzscheme, and not used anywhere particularly; its existence in Arc seems to be accidental.

-----

1 point by dpara 6377 days ago | link

aah beautiful, forget I ever said anything :)

-----

1 point by almkglor 6377 days ago | link

  foo:bar
  ==> (compose foo bar)
  ~foo
  ==> (complement foo)

  foo!bar
  ==> (foo 'bar)
  foo.bar ; no spaces
  ==> (foo bar)

-----

More