rxi / fe

A tiny, embeddable language implemented in ANSI C
MIT License
1.3k stars 81 forks source link

Check amount of passed arguments #17

Closed thacuber2a03 closed 1 year ago

thacuber2a03 commented 1 year ago

how would I check the amount of arguments the user passed to a function, or at least check if there's an argument after the current one? I wanna make a function with 4 optional arguments

ooichu commented 1 year ago

Method 1:

(= my-func (fn (arg opt-1 opt-2 opt-3 opt-4)
  ; do something with that
))

Method 2:

(= my-func (fn (arg . opt)
  ; now, 'opt' is list of arguments after 'arg'
))

If you're asking about writing a C function for fe, you should check the argument list before getting an optional argument (via fe_nextarg) to see if it is nil (via fe_isnil). If the argument list is nil, it means that there are no further arguments.

thacuber2a03 commented 1 year ago

I figured it out a long time ago, but still thanks lol