Clojure-Intro-Course / clojure-intro-class

NOTE: This repository is obsolete. Was: A pilot project to use Clojure for introductory computer science courses at the University of Minnesota - Morris
20 stars 3 forks source link

arity errors on transducer functions #80

Open leek5pin opened 9 years ago

leek5pin commented 9 years ago

Error: You cannot pass three arguments to a function into, need two.

(into to from) (into to xform from)

xform is a transducer

leek5pin commented 9 years ago

I fixed this, and have decided to open a more general problem relating to a few other functions.

leek5pin commented 9 years ago

I forgot to make tests.

leek5pin commented 9 years ago

drop also has the same problem. I will need to go down the list of functions that produce a transducer when an argument is omitted, and update preconditions, and add tests.

map cat mapcat filter remove take take-while take-nth drop drop-while replace partition-by partition-all keep keep-indexed map-indexed distinct interpose dedupe random-sample

elenam commented 9 years ago

Is there a special error when a wrong type of function passed as 'xfrom', or is it just an arity error?

leek5pin commented 9 years ago

(into [] + [1 2 3 4 5 6]) Error: In function +, the first argument conj! must be a number but is a function.

(println (into [] even? [1 2 3 4 5 6])) Error: In function even?, the first argument conj! must be an integer number but is a function.

elenam commented 9 years ago

I mean the original error, not a processed one.

elenam commented 9 years ago

But conj! is an issue here, obviously.

leek5pin commented 9 years ago

Oh, then it's just an arity error.

elenam commented 9 years ago

Do we need two cases, based on whether the functions map, into, etc are used as transducers, or not? Because the arguments are different in these two cases.

leek5pin commented 9 years ago

Yes, this is what I currently have written for into.

(defn into

([argument1 argument2] {:pre [(check-if-seqable? "into" argument1) (check-if-seqable? "into" argument2)]} (clojure.core/into argument1 argument2))

([argument1 argument2 argument3] {:pre [(check-if-seqable? "into" argument1) (check-if-function? "into" argument2) (check-if-seqable? "into" argument3)]} (clojure.core/into argument1 argument2 argument3)))

elenam commented 9 years ago

Ok, that's fine for now, but we should look more into it later.

leek5pin commented 9 years ago

I agree.

elenam commented 8 years ago

For now we will be disallowing transducers versions of common functions. Eventually will need a flag to allow them or not.