Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Scheme help
Index -> Programming, General Programming -> Functional Programming
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
chrisbrown




PostPosted: Sat Jan 16, 2010 8:20 pm   Post subject: Scheme help

I've run into an interesting dilema:

I have a function that consumes a natural number n and produces a list of length n, where each item is a result of a (read) call:
Scheme:
(define (make-list n)
  (cond [(zero? n) empty]
        [else (cons (read) (make-list (sub1 n)))]))


I also have this function which consumes a function, determines its arity (the number of parameters it consumes), and returns a (make-list) of that length
Scheme:
(define (param-list f)
  (define n (procedure-arity f))
  (make-list n))



My question is this: is there some way for test-fcn to return the result of f with the values in plist as its arguments? (Assuming f takes a constant number of arguments)
Scheme:
(define (test-fcn f)
  (define plist (param-list f)))
;;  ???)

;; ??? should be the result of (f (first plist) (second plist) ... (last plist)) where plist is of arbitrary length

;; Edit: ??? = (apply f plist)



Nevermind, found the solution.
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, General Programming -> Functional Programming
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 1 Posts ]
Jump to:   


Style:  
Search: