Arc Forumnew | comments | leaders | submit | wfarr's commentslogin
1 point by wfarr 6079 days ago | link | parent | on: One-to-many, many-to-many, etc

The former, ideally.

-----

1 point by wfarr 6080 days ago | link | parent | on: One-to-many, many-to-many, etc

I know someone made scaffolding work earlier, but I don't know exactly how they did it.

Anyway, ideally with templates -- in my case, one for posts and one for tags -- you'd be able to make use of this relation in a functional way with no real performance issues.

-----

3 points by drcode 6079 days ago | link

I was the one who created the scaffolding system- It does, indeed, generate the code to add/update/etc from a database. I've continued to expand the system on my own, but since there wasn't much interest in the arc forum I decided not to continue checking code into anarki for now, but may again in the future- So right now it is strictly ver 0.01, though I'm surprised others seem to manage without a scaffolding system...

As for the issue of one-many and many-many, I guess I would suggest that in a one-to-many situation I would try and store the "many" as a child field in the "one", not use two separate tables if you can get away with it (one of the advantages of a non-RDBMS is that this design is possible)

As for many-many, I would probably have two tables, then have an extra table that just maps keys to keys for the two tables. Basically, just like an RDBMS association table. (or maybe even a bidirectional table, if you need to go "both ways")

If you want to know the "official" way to store data in different relationships in a simple, purely functional, memory resident database, I'd look at HApps-ixset. This is philisophically closely aligned to what you'd need in arc and is designed by some super smart guys. Unfortunately, their documentation is wanting or I'd point you to a good link that describes how to use it.

Those are some thoughts.

-----

2 points by skenney26 6078 days ago | link

I've been thinking it might be possible to make these mappings implicit. Imagine you had a version of deftem (I'll call it defitem) that inspected the fields in your templates:

  (defitem post
    id     nil
    title  nil
    text   nil
    tags   nil)

  (defitem tag
    id     nil
    text   nil
    post   nil)
defitem would see that post has a relationship with tag and tag has a relationship with post by looking at the names of the fields in each template. Since the post field in tag is singular and the tags field in post in plural, it would know that there is a one-to-many relationship between post and tag. Then defitem could create any necessary accessor methods.

Anyways, that's what I've been attempting recently.

-----

1 point by wfarr 6086 days ago | link | parent | on: defmacro mac?

Personally (and this may well just be me) I prefer the latter.

-----

1 point by dreish 6086 days ago | link

What does it buy you, other than four more steps toward carpal-tunnel syndrome?

-----

1 point by wfarr 6098 days ago | link | parent | on: Cant get tutorial hello webapp to work

Are you using Arc2, or Anarki?

-----


In arc, this is denoted with the "." just like in Scheme.

For example, an argument list for '+ might look like so:

  (a b . rest)
'rest would take the value of everything after '(a b).

-----

3 points by cchooper 6098 days ago | link

Just to add: if you want your function to take any number (including zero) arguments, then just use a symbol instead of an argument list, and all the arguments will be bound to that symbol.

  (def return-all-args x x)

  (return-all-args 1 2 3)
  => (1 2 3)

-----

1 point by krg 6094 days ago | link

globalrev, this stuff confused me at first too.

So if you have (def foo (a b . c) ...stuff...) and you call (foo 1 2 3 4 5), a is bound to 1, b is bound to 2, and c is bound to the list (3 4 5).

And (def foo a ...stuff...) is just shorthand for (def foo ( . a) ...stuff...). So calling (foo 1 2 3) in this case means a is bound to the list (1 2 3).

-----

3 points by almkglor 6094 days ago | link

> And (def foo a ...stuff...) is just shorthand for (def foo ( . a) ...stuff...).

Technically wrong: ( . a) is invalid syntax. However it does help to think of it that way.

-----

2 points by wfarr 6098 days ago | link | parent | on: Suggestion for two core features

1) Not feasible currently. 'foo.bar expands to (foo bar), so you're example would expand to (x y z), or ((1 2 3) (4 5 6) (7 8 9)) where (1 2 3) is being applied as a function.

While it could be implemented, I think it would only serve to further confuse existing syntax.

2) This require some serious hackery on integers to get that to work.

-----

3 points by cchooper 6098 days ago | link

1) Good point. I should have written

  (x!y!z)
  => (1 2 3 4 5 6 7 8 9)
Edit: not I shouldn't! The first way was right.

2) I don't think so. I can't see this is much different to having lists or hashes in functional place.

-----

3 points by eds 6098 days ago | link

Actually, (2) is quite trivial (in Anarki):

  (defcall int (n f)
    (eval (cons 'compose (n-of n f))))
But of course this means you can't use the current version of infix math at the same time.

-----

1 point by wfarr 6098 days ago | link | parent | on: small problem: (def power (nbr power)...

Okay - here's your problem: 'for from 0 to -1 doesn't run at all. So essentially, you're only returning 'acc right now.

I'll paste a fixed function soon-ish.

EDIT: Look at cchooper's post.

-----

1 point by wfarr 6098 days ago | link | parent | on: small problem: (def power (nbr power)...

I believe so.

Because the 'def macro uses '= to define functions, variables and functions are occupying the same namespace (sort of).

For example:

  (def foo () (prn "bar"))
is expanded to:

  (= foo (fn () (prn "bar")))
For example:

  > (def foo () (prn "bar"))
  #<procedure: foo>
  > (= foo "foo")
  "foo"
  > (foo)
  Error: "procedure ...r/src/arc/ac.scm:1224:11: expects 2 arguments, given 1: \"foo\""
Make sense?

Though, that may not affect your usage here since power is just an argument and not a variable itself.

-----

1 point by wfarr 6098 days ago | link | parent | on: small problem: (def power (nbr power)...

Your function works fine for me on Anarki?

-----

1 point by cchooper 6098 days ago | link

Doesn't work on Arc2 for negative powers.

-----

1 point by globalrev 6098 days ago | link

works for (power 5 0), (power 5 2) but not (power 5 -2)

raising power to a negative number returns 1.

-----

1 point by wfarr 6098 days ago | link

Ah - I'll take a gander at that.

-----

1 point by wfarr 6098 days ago | link | parent | on: Learningcurve of LISP?

The learning curve is quite small. You're just learning a different thinking process than you're used to.

It might help for you to read "The Roots of Lisp" by Paul Graham, which will not only explain Lisp's core axioms, but also show you how they form other things in the language.

After that, I'd see if you can find a copy of "The Little Schemer" by Daniel P. Friedman and Matthis Felleisen, which will not only introduce you to sound functional concepts through the use of recursion, but do so by helping you write functions which are actually quite useful.

There is of course, much more literature out there that will go far more in-depth into Lisp, but these will provide a gentle introduction to the basics.

-----

1 point by jmatt 6098 days ago | link

The learning curve is small if you have a math or cs education, if you've been exposed to another functional language or you naturally think in s-expressions.

If you are just a random python programmer and you looked at arc I could see it being challenging. The axioms of lambda calculus and functional programming are concise and simple but that doesn't mean the concepts they imply are also simple.

I agree The Little Schemer is a great book. Along with SICP, On Lisp, etc.

In the end it is worth the trouble to learn at least one lisp dialect. It'll improve your coding and make you question why you are writing imperative-language-001 all day long.

-----

4 points by wfarr 6098 days ago | link

Having come from Perl, Python, and Ruby I didn't have much trouble.

Granted, Ruby makes use of closures and anonymous functions more often than the other two.

I think the greatest learning tool I had was configuring my Emacs setup and writing extensions to do things I wanted in my workflow.

-----

More