Arc Forumnew | comments | leaders | submit | dpkendal's commentslogin

The first one is clearly in issue. I propose also to replace reduce with this (happily, tail-recursive) version:

    (def reduce (f xs)
      ((rfn rdc (a s)
        (if (no s)
          a
          (rdc (f a (car s)) (cdr s)))) (car xs) (cdr xs)))
which avoids this problem by returning nil when `xs` is nil.

However, I would consider the second issue to be merely incidental. It is still a correct result.

-----

2 points by thaddeus 4926 days ago | link

I wouldn't assume something is incidental unless the purpose has been researched. And, I believe, its correctness can only be determined by its intended use... Which is why I was kinda suggesting someone check where and why it's actually used.

As a guess, 'best' is probably used for http://arclanguage.org/best in the news.arc code. In which case it's probably not an issue... ?

At any rate, references should probably be checked? Or maybe, instead, news.arc code should be dropped from anarki? Could it be that supporting news.arc only stifles arc's development?

-----

2 points by rocketnia 4926 days ago | link

I think supporting anything stifles development. It's a contradiction I just try to accept. :-p

I don't see the purpose of 'best. I don't see a bigger purpose in most of Arc. If what Arc gives me isn't what I need, I reinvent it.

(In fact, I think if we try to keep working on the same language, rather than tearing it down and reinventing it, we're worrying about at least some kind of "support" and stifling our development. But too much tearing down can be destructive too, of course. :-p I appreciate that you're applying a scientific-ish mindset to this.)

There are a few ways to cut through this Arc ennui:

- If Arc gives me tools I can use to reinvent things, those tools are extra-relevant, since even if I don't like them I'll use them on my way to replacing them. This is not something 'best does for me.

- Sometimes we may want everyone in the language community to use the same variant of something, so that the tools we build around that thing can work together. Are we trying to optimize 'best in the compiler/runtime? Nope. Do people often extend 'best with extra capabilities? Nope. Even if these things were true, are we even having an issue with people reinventing 'best all the time? Nope, I don't think so.

- Do I still kinda like to discuss it? Yep. :-p

-----

3 points by thaddeus 4926 days ago | link

I agree with everything you're saying... and, also, in thinking about it further, I believe that having namespaces as a first class feature is the best way to solve this kinda problem.

For example, in Clojure, I can just build my project by excluding the function in question and replace it with my version. Anyone else that wants to use Clojure doesn't need to worry about another persons great idea.

; example

  (ns a-project.core
    (:refer-clojure :exclude (best))
    (:gen-class))
  
  (defn best []
    ...)
And anyone else wanting to use my library and/or only use my version can do so, simply:

  (ns your-project.core
    (:refer-clojure :exclude (best))
    (:use [a-project :only (best)])
    (:gen-class))
   
   (defn do-my-stuff []
    (best ....))
And I can't even remember now - did anarki get namespaces? I know there were some implementations, I just don't know if it made its way into anarki.

I also believe namespaces would promote the sharing of libraries, which arc also suffers from.

-----

1 point by rocketnia 4926 days ago | link

I think it's cleaner to define 'reduce in terms of 'foldl:

  (def reduce (func xs)
    (whenlet (x . xs) xs
      (foldl func x xs)))
But I don't even really want 'reduce. If the function is '+, an empty list should give 0. If the function is '*, an empty list should give 1. Instead of trying to divine this value from nowhere, I think it makes more sense to pass the base case manually, as with 'foldl.

Alternatively we could have this...

  (def reduce (func xs)
    (iflet (x . xs) xs
      (foldl func x xs)
      (func)))
...but if the function is set up to take different numbers of arguments, we probably should have done (apply func xs) in the first place.

-----

1 point by dpkendal 5142 days ago | link | parent | on: Binary search in Arc

Either of these are neater than using `and`, which for clarity is better only used as a predicate, in my opinion.

Thanks fallintothis, zck, and shader for your improvements. I'm trying to take everyone's suggestions into account to make a new version, which I'll put in Anarki when I'm satisfied with it.

-----

1 point by dpkendal 5142 days ago | link | parent | on: Binary search in Arc

> You're missing the case where the haystack is emtpy [sic]

D'oh! That was an obvious case to miss. Thanks for your optimisations, I'll look into combining these with fallintothis's.

-----

4 points by dpkendal 5163 days ago | link | parent | on: Textile for Arc 0.1

> The fact that you're not escaping HTML characters troubles me. I'd kinda prefer not to risk encountering malevolent JavaScript on a forum, even on a forum where most regulars wouldn't abuse that power.

The original classTextile.php (http://code.google.com/p/textpattern/source/browse/developme... -- warning: big) provides a 'restricted' mode, designed for forum comments etc., in which all input <, > and & characters are escaped, which is what I intend to do here as I continue to work on it.

> It strikes me that this wouldn't handle nesting well, which may be fine, 'cause these spans are things people almost never need to nest--some exceptions being when attributes are involved or when nesting multiple layers of <sup> and <sub>. To make it a bit less sloppy, I recommend manually incrementing an index through the text, using 'begins to identify start tags and maintaining a stack if necessary, even if it sounds horribly ugly to do it that way. :-p This should also give you a good place to insert attribute-parsing code.

While you're right about the attribute-parsing, I'm not too concerned about nesting issues because the current reference implementation (there's a dingus at http://textile.sitemonks.com/) doesn't handle that either. It uses the regexp method too (see classTextile.php), with a callback for parsing attributes.

> Speaking of spans, I'm not sure why you bother making all the txt-@ global variables. I think all you do is use 'eval to define them and another 'eval to get them back, and you don't even need the second 'eval because you have all the information you need.

Thanks. I've now corrected my copy and I'll use your method in the next version.

> Also speaking of spans, I'm troubled by the fact that there's a -del- span at all. I hope this syntax doesn't apply to every instance of a hyphen before a whitespace character, 'cause that'll mess up a lot of variable names and links.

> Speaking of which, lots of links have +pluses+ in them as URL-encoded spaces, so that's a troublesome syntax too. What does Textile do in these cases?

Good point, that's a special case I missed. The function is now:

    (def txt-span (text st et tag) ; st = start textile; et = end textile -- todo: support span attributes
      (re-replace (string "(?<=\\W|^)" (txt-re-quote st) "(\\S.*?\\S?)" (txt-re-quote et) "(?=\\W|$)") text (string "<" tag ">" #\\ 1 "</" tag ">")))
(notice the lookarounds at each end) which should prevent such issues.

> I realize you're in the earlier stages of getting to know Arc, and I don't mean to discourage you or anything. I only mean to contribute. ^_^

Yes! Thank you for your contribution -- it's for advice like this that I released so early.

> The suggestion that comes to my mind is this, but it's kinda laughable....

Yeah, I'll stick with my `str-split` for now. It should be a library function anyhow, so I'd rather keep my version short and simple until there's a version in `strings.arc` or `arc.arc`.

> Apparently you can just keep using 're-replace but pass a function as the "replacement" argument. It appears to work very much like preg_replace_callback(), except that each captured string is passed as a separate argument rather than in an array

Aha, I don't know why I didn't think to try that. I just mentally assumed I would need another function to do it.

Thanks for all your help! I really appreciate it.

(There's now a textile repo at https://github.com/dpkendal/textile, into which I'll slowly be putting improvements.)

-----


I've seen the latter style in other people's code, and I do indeed use it for shorter functions with small amounts of indentation. I use BBEdit, which does have a balance option, (Command-B) but I still like to be able to see when something's out of line at a glance with longer functions. I don't mind either style, though.

-----


This is the beginnings of an implementation of Textile in Arc. The main textile routine is empty; txt-block doesn't work because re-split, despite being in re.arc, doesn't seem to work (at least for me), so the two main working things are txt-html-block, which needs a couple variables to be defined in order to work, and txt-span and friends, which perform the standard span-like substitutions, without attributes as yet. There are probably gotchas in both routines.

-----


It's not that they're troublesome to render in simple circumstances, but consider:

1. Alice is writing a blog entry declaring her unrequited love for Bob.

2. Alice includes a quote from Bob's blog by copying-and-pasting. Bob is using UTF-8 charset, and the copied section includes some Unicode curled quotes, because Bob is typographically sensitive.

3. Because Alice is using a backwards text editor which refuses to believe there is something other than 1 byte = 1 character and plain ASCII in the lower half, it shows the characters exactly as Alice and Bob intended (such a third-rate text editor is sure to be using the operating system's standard text editing control, which will know about such tricks) -- but internally it has crapped up the representation, and lo:

4. When Alice submits this onto her ISO-8859-1-encoded blog, she will have mixed character sets and invalid XML and all of a sudden her well-written love letter is smeared by �s where there ought to be “s and ”s.

Further reading:

- http://textism.com/article/663/pomegranate

- http://daringfireball.net/2003/02/short_and_curlies

- http://www.alistapart.com/articles/emen/

-----

1 point by aw 5199 days ago | link

Ah, I understand. Your goal is to encode Unicode text in HTML which is itself encoded in ASCII only, so it can be transmitted through channels (such as bad editors) which mess up non-ASCII text.

To encode any Unicode text this way we'd also want to encode HTML special characters such as <, >, and &; but that could be done before calling your routine.

-----


Thanks. Didn't know coerce could be used like that.

-----