how to limit memory in script ?

Currently from command line ,I am setting memory like :
q -w 500

but when I require it within a script what would be the way..‘system’ command ? not sure

Is there any other way /approach to limit the memory too ?

There doesn’t appear to be a way to change the maximum memory that q uses with “system”:
  http://code.kx.com/wiki/Reference/SystemCommands#.5Cw_.5B0.5D_-_workspace