Arc Forumnew | comments | leaders | submitlogin
Predicates: `is...' versus `...?'
7 points by pgwoden 6100 days ago | 20 comments
The names of many predicates in Arc begin with `is', while in Scheme they typically end with a final question mark. IMHO either approach is certainly better than CL's haphazard use of a final `P' to denote a predicate. Personally, I'm fond of Scheme in this regard: it's concise and easily recognizable. What are people's views on one versus the other?


3 points by rincewind 6100 days ago | link

I think this should not be embedded into function names. My Idea: Arc IDEs could instead manage attributes for names like "predicate", "has side effects", or "is a global". IDEs would search for such tags in the docstring of a function and syntax-highlight it accordingly. Lisp does not have enough syntax to highlight anyway.

-----

2 points by nex3 6100 days ago | link

I'm about the idea of building IDE support into the language. I'd much prefer a name-based solution.

-----

5 points by absz 6100 days ago | link

You're what about the idea? Ambivalent? Inquiring minds want to know!

EDIT: I'm not trying to be rude, but sometimes the internet does not convey nuance very well. Don't take it that way, if you please.

-----

4 points by nex3 6100 days ago | link

Sometimes people who post to the internet don't proofread their posts :p.

The word I meant to put in there was "dubious." Sorry about that.

-----

2 points by absz 6100 days ago | link

Thank you, good sir.

And I completely concur (great word choice)--I'm working in a text editor right now (TextMate, not Emacs), and it's perfectly suitable. Forcing use of an IDE, or biasing towards it, would turn me away from the language.

-----

1 point by almkglor 6100 days ago | link

Interesting. Care to start hacking the arc-wiki docstrings? I know I haven't even completed the "see also" links ^^

-----

4 points by sacado 6100 days ago | link

I like the Scheme version. However, I think the idea is to keep "?" as a potential syntactic character in the future

-----

7 points by nex3 6100 days ago | link

We could do something akin to Ruby: declare that "?", specifically, is allowed the end of an identifier. This seems to be as good a use as any, and it could still be used as a prefix or infix syntactic character.

-----

1 point by Jesin 6099 days ago | link

Why is everyone opposed to foop for predicates? I understand the opposition to foo? (it involves an awkward shift-/ and swallows up one of the most potentially-useful ssyntax characters), but foop is easy to type, easy to read once you've used it for a couple hours, and easy to say. I like CL's last-character naming conventions. They make it easier to see what the code does, and they are quicker and easier to use than Scheme's set! and integer?

Note: this is not coming from a nostalgic Common Lisper. I'm somewhat new to Lisp, and the only Lisps I'm comfortable with are Scheme and Arc. I just think CL naming conventions make a lot of sense.

(I also like the idea of having a function called intp embedded in the language (if you don't know what I mean, look it up).)

-----

2 points by absz 6099 days ago | link

As another new-ish Lisper, comfortable with only Scheme and Arc, I have to disagree. I find appending a character which might anyway occur at the end of a predicate to be a confusing way of expressing predicates. What about a type called, say, tem (a template, perhaps): what's temp? Is it tem predicate or temporary? I actually prefer the "a..." style to the "...p" style, but I think "...?" is still better.

-----

1 point by Jesin 6098 days ago | link

Who would ever use 'tem for anything? A template type would more likely be called temp, and the predicate would be tempp. Usually when p is the next letter, it's included in the variable name, and when a p at the end of a name is part of a word, it is not usually read as predicate. This sort of collision is very rare, and when it does happen, it usually takes no more than a second to figrue out.

On the other hand, asomething in Arc sometimes means anaphoric-something and sometimes means isa-something. This inconsistency is much more common, and a- collisions are no better than -p collisions.

Then there is the foo? of Scheme. Every time I see foo? it interrupts my reading. I don't know about you, but I think of ? followed by a space as a terminator, and putting it between a function name and its arguments throws me off. The ? character also has a lot of potential for ssyntax, and in that position any break it would cause would most likely coincide with a conceptual break. I have no problem with punctuation separating symbols, but when it's punctuation followed by a space, that looks like a pause and throws me off.

-----

2 points by absz 6098 days ago | link

I used tem because I couldn't think of another word quickly, and everyone has seen temp used as a variable name. Your point about anaphoric- versus isa-, though, is a good one; I'd forgotten that, and that's just another reason I like ...? as the terminology. Using single characters can lead to collisions.

When I see (even? n), I read the "even?" as "even" with an upwards tone, not as "even" followed by a separator. Thus, the predicate call reads as a question in my head, which is what it's supposed to be. On the other hand, I find that #'foop reads like the word "foop," which doesn't mean anything. It's less severe with something like #'numberp, but nevertheless, I find ...p to be where the semantic collision lies.

And though you're worried about the removal of ...? as ssyntax, as nex3 pointed out (http://arclanguage.org/item?id=4849), one could explicitly allow a ? at the end, while still allowing it as ssyntax.

-----

1 point by Jesin 6095 days ago | link

And where does most ssyntax go? At the end of identifiers.

Also, consider that

  (foo? 'baz)
can be written as

  foo?!baz
Mixing punctuation like this gets weird.

-----

3 points by absz 6095 days ago | link

Actually, we right now have no ssyntax that goes at the end of identifiers. Arc has ten pieces of syntax. () and [] are circumfix. ' ` , ,@ and ~ are prefix. : . and ! are infix. The two syntax requests I recall off the top of my head were (1) being able to write $(...) for some reason, which is prefix; and (2) being able to write ($f ...) for (map f ...), which is also prefix. So from a preliminary study (admittedly, with very few data points, but that's all there are), it appears that prefix syntax is the most common.

And as for the foo?!baz observation? Don't do that then :) Seriously, I don't think that's a problem. Just because we can write something like ~+:/.3.1@-2.5!-1 doesn't mean we should. (If you're curious, that is currently legal and expands to (compose (complement +) (/ 3 1@-2 5 '-1)) [r@q is notation for the complex number with magnitude r and angle q, just in case you haven't seen it before.]).

EDIT: Used to say "that's actually probably a bug, since I was expecting it to expand to (compose (complement +) (/ 3.1@-2.5 '-1)), but how often will we be putting complex numbers inside ssyntax?," but that was wrong (see http://arclanguage.org/item?id=5090).

-----

2 points by eds 6095 days ago | link

That expansion isn't a bug. You just can't put floating point numbers into ssyntax.

http://arclanguage.org/item?id=2180

-----

1 point by absz 6095 days ago | link

D'oh. How'd I miss that? Thanks.

-----

2 points by lojic 6100 days ago | link

Are you referring to is, isa, iso, isnt, etc. ? If so, what would you propose for those instead?

-----

2 points by treef 6099 days ago | link

i would like the * ? to be a name-marco that would expand to

   [(is (type _) '*]
so

   int? -> [(is (type _) 'int]
   (int? 3)

-----

4 points by nex3 6099 days ago | link

I don't like this. I'd prefer to allow the question mark to be at the end of any predicate. It's pretty simple to define your own type predicates if you need them, but it's not possible to define other question-marked predicates if the syntax is already taken up.

-----

1 point by almkglor 6100 days ago | link

Perversely, I like CL's versoin. foop, foo-p ^^

Note however that Arc's naming conventions are even more haphazard:

http://arclanguage.org/item?id=3604

-----