How to define a variadic function

后端 未结 2 706
甜味超标
甜味超标 2021-02-20 14:17

I\'m looking for something similar to Javascript\'s arguments array:

function parent(){
  child.apply(this.arguments);
}

I\'m awar

2条回答
  •  孤独总比滥情好
    2021-02-20 14:53

    You want:

    (define (parent . args) 
       args) ; args is a list
    

    Which is infact the 'default' implementation of list.

    (define (list . x) x)
    

    The error message when applying (define (parent . ) ...) seems wrong, also, the code should not have compiled in the first place as it is invalid syntax. Might imply a bug with the version of Chicken Scheme you are using.

提交回复
热议问题