Home > Community > Forums > Custom IC SKILL > A printf wrapper


* Required Fields

Recipients email * (separate multiple addresses with commas)

Your name *

Your email *

Message *

Contact Us

* Required Fields
First Name *

Last Name *

Email *

Company / Institution *

Comments: *

 A printf wrapper 

Last post Tue, Aug 12 2008 7:04 AM by dmay. 1 replies.
Started by mb47 12 Aug 2008 01:07 AM. Topic has 1 replies and 2999 views
Page 1 of 1 (2 items)
Sort Posts:
  • Tue, Aug 12 2008 1:07 AM

    • mb47
    • Not Ranked
    • Joined on Thu, Jul 17 2008
    • Posts 3
    • Points 60
    A printf wrapper Reply

    Dear skilled cadencers,

    I'd like to write a wrapper for the printf() function. The problem is
    that I do not know how to have a variable number of arguments. I tried
    with @rest:

    procedure( myPrint(port str @rest args)
        fprintf(port str args)

    however this won't work because args is a list and fprintf (or printf)
    complains about that.
    How can I achieve this task?



    • Post Points: 20
  • Tue, Aug 12 2008 7:04 AM

    • dmay
    • Top 25 Contributor
    • Joined on Thu, Jul 17 2008
    • Allen, TX
    • Posts 393
    • Points 7,415
    Re: A printf wrapper Reply

    Take a look in the Skill Language Reference Index for "Comma-At" documentation. With this syntax you can get your function working:

    procedure( myPrint(port str @rest args)
        apply('fprintf `(,port ,str ,@args) )
    port = outfile("/tmp/test.txt")
    myPrint(port "Hello %s %d" "derek" 1)
    myPrint(port "Hello %s %d" "joe" 2)
    myPrint(port "Hello %s %d" "zeke" 3)

    The documentation states:
    In absence of commas and the comma-at (,@) construction, backquote functions in exactly the same way as single quote. However, if a comma appears inside a backquoted form, the expression that immediately follows the comma is evaluated, and the result of evaluation replaces the original form.
    The comma-at construction causes evaluation just as the comma does, but the results of evaluation must be a list, and the elements of the list, rather than the list itself, replace the original form.


    • Post Points: 5
Page 1 of 1 (2 items)
Sort Posts:
Started by mb47 at 12 Aug 2008 01:07 AM. Topic has 1 replies.