Skip to main content
replaced http://codegolf.stackexchange.com/ with https://codegolf.stackexchange.com/
Source Link

Exceptions

All exceptions are fatal in CJam. Since output to STDERR is ignored by default, we can use this to our advantage.

All operator in CJam work by popping zero or more elements from the stack, perform some task and push zero or more elements on the stack. Exceptions occur while the task is performed, so this still pops the elements, but nothing is pushed in return.

Here are a few use cases:

  • Clearing a small stack

    To clear a stack that contains two elements, @ can be used. @ tries to pop three stack elements, but fails after popping the second.

    Any other operator that pops three elements would serve the same purpose.

    See it in action herehere.

  • Removing two or three elements from the stack

    Any operator that is not implemented for these particular elements can be used to pop two or three elements from the stack right before exiting.

    To pop two elements, b works if one of them is a character or none of them is an integer.

    To pop three elements, t works if none of the bottom-most two is an iterable, the bottom-most iterable is empty or none of them is an integer.

  • Exiting from a loop

    On occasions, we need to exit from a loop when an integer becomes zero or a string becomes too short. Rather than testing for these conditions, if the involved operations fail for zero, the empty string or singletons, we can simply let the program take its natural course.

    For an example involving arithmetic, see herehere.

    For an example involving strings, see herehere.

  • Conditional execution

    If the source code should not be executed for certain types of input, we sometimes can use an operator that fails that kind of input.

    For example, i will fail for strings that do not evaluate to an integer and ew will fail for strings of length 0 or 1.

    See it in action herehere.

Exceptions

All exceptions are fatal in CJam. Since output to STDERR is ignored by default, we can use this to our advantage.

All operator in CJam work by popping zero or more elements from the stack, perform some task and push zero or more elements on the stack. Exceptions occur while the task is performed, so this still pops the elements, but nothing is pushed in return.

Here are a few use cases:

  • Clearing a small stack

    To clear a stack that contains two elements, @ can be used. @ tries to pop three stack elements, but fails after popping the second.

    Any other operator that pops three elements would serve the same purpose.

    See it in action here.

  • Removing two or three elements from the stack

    Any operator that is not implemented for these particular elements can be used to pop two or three elements from the stack right before exiting.

    To pop two elements, b works if one of them is a character or none of them is an integer.

    To pop three elements, t works if none of the bottom-most two is an iterable, the bottom-most iterable is empty or none of them is an integer.

  • Exiting from a loop

    On occasions, we need to exit from a loop when an integer becomes zero or a string becomes too short. Rather than testing for these conditions, if the involved operations fail for zero, the empty string or singletons, we can simply let the program take its natural course.

    For an example involving arithmetic, see here.

    For an example involving strings, see here.

  • Conditional execution

    If the source code should not be executed for certain types of input, we sometimes can use an operator that fails that kind of input.

    For example, i will fail for strings that do not evaluate to an integer and ew will fail for strings of length 0 or 1.

    See it in action here.

Exceptions

All exceptions are fatal in CJam. Since output to STDERR is ignored by default, we can use this to our advantage.

All operator in CJam work by popping zero or more elements from the stack, perform some task and push zero or more elements on the stack. Exceptions occur while the task is performed, so this still pops the elements, but nothing is pushed in return.

Here are a few use cases:

  • Clearing a small stack

    To clear a stack that contains two elements, @ can be used. @ tries to pop three stack elements, but fails after popping the second.

    Any other operator that pops three elements would serve the same purpose.

    See it in action here.

  • Removing two or three elements from the stack

    Any operator that is not implemented for these particular elements can be used to pop two or three elements from the stack right before exiting.

    To pop two elements, b works if one of them is a character or none of them is an integer.

    To pop three elements, t works if none of the bottom-most two is an iterable, the bottom-most iterable is empty or none of them is an integer.

  • Exiting from a loop

    On occasions, we need to exit from a loop when an integer becomes zero or a string becomes too short. Rather than testing for these conditions, if the involved operations fail for zero, the empty string or singletons, we can simply let the program take its natural course.

    For an example involving arithmetic, see here.

    For an example involving strings, see here.

  • Conditional execution

    If the source code should not be executed for certain types of input, we sometimes can use an operator that fails that kind of input.

    For example, i will fail for strings that do not evaluate to an integer and ew will fail for strings of length 0 or 1.

    See it in action here.

added 4 characters in body
Source Link
Dennis
  • 210.6k
  • 41
  • 370
  • 825

Exceptions

All exceptions are fatal in CJam. Since output to STDERR is ignored by default, we can use this to our advantage.

All operator in CJam work by popping zero or more elements from the stack, perform some task and push zero or more elements on the stack. Exceptions occur while the task is performed, so this still pops the elements, but nothing is pushed in return.

Here are a few use cases:

  • Clearing a small stack

    To clear a stack that contains two elements, @ can be used. @ tries to pop three stack elements, but fails after popping the second.

    Any other operator that pops three elements would serve the same purpose.

    See it in action here.

  • Removing two or three elements from the stack

    Any operator that is not implemented for these particular elements can be used to pop two or three elements from the stack right before exiting.

    To pop two elements, b works if one of them is a character or none of them is an integer.

    To pop three elements, t works if none of the bottom-most two is an iterable, the bottom-most iterable is empty or none of them is an integer.

  • Exiting from a loop

    On occasions, we need to exit from a loop when an integer becomes emptyzero or a string becomes totoo short. Rather than testing for these conditions, if the involved operations fail for zero, the empty string or singletons, we can simply let the program take its natural course.

    For an example involving arithmetic, see here.

    For an example involving strings, see here.

  • Conditional execution

    If the source code should not be executed for certain types of input, we sometimes can use an operator that fails that kind of input.

    For example, i will fail for strings that do not evaluate to an integer and ew will fail for strings of length 0 or 1.

    See it in action here.

Exceptions

All exceptions are fatal in CJam. Since output to STDERR is ignored by default, we can use this to our advantage.

All operator in CJam work by popping zero or more elements from the stack, perform some task and push zero or more elements on the stack. Exceptions occur while the task is performed, so this still pops the elements, but nothing is pushed in return.

Here are a few use cases:

  • Clearing a small stack

    To clear a stack that contains two elements, @ can be used. @ tries to pop three stack elements, but fails after popping the second.

    Any other operator that pops three elements would serve the same purpose.

    See it in action here.

  • Removing two or three elements from the stack

    Any operator that is not implemented for these particular elements can be used to pop two or three elements from the stack right before exiting.

    To pop two elements, b works if one of them is a character or none of them is an integer.

    To pop three elements, t works if none of the bottom-most two is an iterable, the bottom-most iterable is empty or none of them is an integer.

  • Exiting from a loop

    On occasions, we need to exit from a loop when an integer becomes empty or a string becomes to short. Rather than testing for these conditions, if the involved operations fail for zero, empty string or singletons, we can simply let the program take its natural course.

    For an example involving arithmetic, see here.

    For an example involving strings, see here.

  • Conditional execution

    If the source code should not be executed for certain types of input, we sometimes can use an operator that fails that kind of input.

    For example, i will fail for strings that do not evaluate to an integer and ew will fail for strings of length 0 or 1.

    See it in action here.

Exceptions

All exceptions are fatal in CJam. Since output to STDERR is ignored by default, we can use this to our advantage.

All operator in CJam work by popping zero or more elements from the stack, perform some task and push zero or more elements on the stack. Exceptions occur while the task is performed, so this still pops the elements, but nothing is pushed in return.

Here are a few use cases:

  • Clearing a small stack

    To clear a stack that contains two elements, @ can be used. @ tries to pop three stack elements, but fails after popping the second.

    Any other operator that pops three elements would serve the same purpose.

    See it in action here.

  • Removing two or three elements from the stack

    Any operator that is not implemented for these particular elements can be used to pop two or three elements from the stack right before exiting.

    To pop two elements, b works if one of them is a character or none of them is an integer.

    To pop three elements, t works if none of the bottom-most two is an iterable, the bottom-most iterable is empty or none of them is an integer.

  • Exiting from a loop

    On occasions, we need to exit from a loop when an integer becomes zero or a string becomes too short. Rather than testing for these conditions, if the involved operations fail for zero, the empty string or singletons, we can simply let the program take its natural course.

    For an example involving arithmetic, see here.

    For an example involving strings, see here.

  • Conditional execution

    If the source code should not be executed for certain types of input, we sometimes can use an operator that fails that kind of input.

    For example, i will fail for strings that do not evaluate to an integer and ew will fail for strings of length 0 or 1.

    See it in action here.

Source Link
Dennis
  • 210.6k
  • 41
  • 370
  • 825

Exceptions

All exceptions are fatal in CJam. Since output to STDERR is ignored by default, we can use this to our advantage.

All operator in CJam work by popping zero or more elements from the stack, perform some task and push zero or more elements on the stack. Exceptions occur while the task is performed, so this still pops the elements, but nothing is pushed in return.

Here are a few use cases:

  • Clearing a small stack

    To clear a stack that contains two elements, @ can be used. @ tries to pop three stack elements, but fails after popping the second.

    Any other operator that pops three elements would serve the same purpose.

    See it in action here.

  • Removing two or three elements from the stack

    Any operator that is not implemented for these particular elements can be used to pop two or three elements from the stack right before exiting.

    To pop two elements, b works if one of them is a character or none of them is an integer.

    To pop three elements, t works if none of the bottom-most two is an iterable, the bottom-most iterable is empty or none of them is an integer.

  • Exiting from a loop

    On occasions, we need to exit from a loop when an integer becomes empty or a string becomes to short. Rather than testing for these conditions, if the involved operations fail for zero, empty string or singletons, we can simply let the program take its natural course.

    For an example involving arithmetic, see here.

    For an example involving strings, see here.

  • Conditional execution

    If the source code should not be executed for certain types of input, we sometimes can use an operator that fails that kind of input.

    For example, i will fail for strings that do not evaluate to an integer and ew will fail for strings of length 0 or 1.

    See it in action here.