Thanks! That might be the first thing I learn from lisp where things work fundamentally different than ruby. This gives some interesting possibilities.
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?
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.
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.
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?
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.
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?
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.
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.
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.
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.
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.
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))))
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 ;)
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.