#92 $@ and $# expansion (argc, argv)

wishlist
open
puredata (375)
5
2006-08-21
2006-08-21
No

the attached patch extends the $-expansion mechanism:

$# expands to the number of arguments; usable both as
A_DOLLAR (just "$#") and A_DOLLSYM ("$#-bla")

$@ expands to the entire list of arguments (e.g. [$@
$@( will expand [1 2 3( to [1 2 3 1 2 3(); this is only
usable as A_DOLLAR; i.e. [symbol $@-a( will always
expand to "$@-a"

why:
well, its a way to deal with dynamic length lists that
is still missing in pd (though 1st steps have been made
with [list])

caveats:
what is still missing is an expansion for the selector
of messages and objects (the selector of an object
would be the object's instantation name); would $$ be a
good name for this? (since $0 is already taken)

Discussion

  • Logged In: YES
    user_id=27104

    Yes! This is great!

    As for the selector, $0 is not taken in message space, so I
    think it makes sense there. Since message expansion
    variables are already different than object arguments, I
    think that won't be too confusing. Plus the $ variable
    syntax comes from shell scripting, where $0 is basically the
    selector of the message that is the command line arguments.

     
  • Logged In: YES
    user_id=564396
    Originator: YES

    updated for current CVSversion of pd (2007-01-02)
    File Added: dollargcargv.patch

     
  • Logged In: YES
    user_id=801174
    Originator: NO

    i think that $@ is what is necessary to allow abstractions to do what they want with args, and that $# is not so useful in comparison, and what would be more useful than $# (in the sense of avoiding more detours) would be to be able to do a $@-like thing that only starts at the Nth argument, e.g. if I have an abstraction that takes $1 $2 $3 and then a variable number of arguments, and those arguments starting with $4 are to be all written directly in an objectbox. witness the strange stuff going on in [nqpoly]...

     


Anonymous


Cancel   Add attachments