`partial` won't work here because you're partially applying *two* 
arguments, `type` and the :idVe portion of the &rest args.  `partial` only 
lets you override an *unbroken* sequence of args at the *beginning* of the 
arglist.
For instance, (partial log "DEBUG" "default message") would work.  To 
override some of the &rest args, you need to use `apply`:

user=> (defn debug-com [msg & args] (apply log "DEBUG" msg :idVe "COM" args
))
user=> (debug-com "message")
LOCAL: DEBUG -> message <- COM
nil
user=> (debug-com "message" :id "REMOTE")
REMOTE: DEBUG -> message <- COM
nil

If it really needs to be an anonymous function, `fn` works with the same 
syntax.

Happy hacking,
Leif

On Tuesday, February 23, 2016 at 3:14:58 PM UTC-5, Fernando Abrao wrote:
>
> Hello, it worked, but if I use
>
> (debug "TEST" :id "something")
>
> is getting ArityException Wrong number of args (3) passed to ...
>
> Em terça-feira, 23 de fevereiro de 2016 15:36:46 UTC-3, Josh Tilles 
> escreveu:
>>
>> My guess is that what you're looking for is:
>> (def debug #(log "DEBUG" % :idVE "COM"))
>> (see "Anonymous function literal" under 
>> http://clojure.org/reference/reader#_dispatch)
>>
>> However, note that defining functions in a "point-free"-ish style in 
>> Clojure has a downside with regard to metadata, in that the function 
>> arities and argument names aren't inspectable at the REPL:
>> (def debug-1 #(log "DEBUG" % :idVE "COM"))
>> ;= user/debug-1
>> (clojure.repl/doc debug-1)
>> ; -------------------------
>> ; user/debug-1
>> ;   nil
>> ;= nil
>> (defn debug-2 [message]
>>   (log "DEBUG" message :idVE "COM"))
>> ;= user/debug-2
>> (clojure.repl/doc debug-2)
>> ; -------------------------
>> ; user/debug-2
>> ; ([message])
>> ;   nil
>> ;= nil
>>
>>
>> Hope that's helpful,
>> Josh
>>
>> P.S. If you *really want to* you can populate the :arglists metadata 
>> yourself:
>> (def ^{:arglists '([message])} debug #(log "DEBUG" % :idVE "COM"))
>>
>>
>>
>> On Tuesday, February 23, 2016 at 1:14:33 PM UTC-5, Fernando Abrao wrote:
>>>
>>> Hello all,
>>>
>>> I´m trying to do something like:
>>>
>>> (defn log [type message & {:keys [id idVe] :or {id "LOCAL" idVe "END"}}] 
>>>      (println (str id ": " type " -> " message "<- " idVe)))
>>>
>>>
>>> (def debug (partial log "DEBUG" ?? :idVe "COM"))
>>>
>>>
>>> Is there any way to do what I want? Pass arguments to log and add the 
>>> :idVe into the end? Is the partial the best using to do this?
>>>
>>> Regards,
>>>
>>> Fernando
>>>
>>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to