class Whatever

Placeholder for the value of an unspecified argument
class Whatever { }

Whatever is a class whose objects don't have any explicit meaning; it gets its semantics from other routines that accept Whatever-objects as markers to do something special. Using the * literal as an operand creates a Whatever object.

Much of *'s charm comes from Whatever-priming. When * is used in term position, that is, as an operand, in combination with most operators, the compiler will transform the expression into a closure of type WhateverCode, which is actually a Block that can be used wherever Callables are accepted.

my $c = * + 2;          # same as   -> $x { $x + 2 };
    say $c(4);              # OUTPUT: Ā«6ā¤Ā»

Multiple * in one expression generate closures with as many arguments:

my $c = * + *;          # same as   -> $x, $y { $x + $y }

Using * in complex expressions will also generate closures:

my $c = 4 * * + 5;      # same as   -> $x { 4 * $x + 5 }

Calling a method on * also creates a closure:

<a b c>.map: *.uc;      # same as    <a b c>.map: -> $char { $char.uc }

As mentioned before, not all operators and syntactic constructs prime * (or Whatever-stars) to WhateverCode. In the following cases, * will remain a Whatever object.

Exception Example What it does
comma 1, *, 2 generates a List with a * element
range operators 1 .. * Range from 1 to Inf
series operator 1 ... * infinite lazy Seq
assignment $x = * assign * to $x
binding $x := * bind * to $x
list repetition 1 xx * generates an infinite list

The range operators are handled specially. They do not prime with Whatever-stars, but they do prime with WhateverCode

say (1..*).^name;       # OUTPUT: Ā«Rangeā¤Ā»
    say ((1..*-1)).^name;   # OUTPUT: Ā«WhateverCodeā¤Ā»

This allows all these constructs to work:

.say for 1..*;          # infinite loop

and

my @a = 1..4;
    say @a[0..*];           # OUTPUT: Ā«(1 2 3 4)ā¤Ā»
    say @a[0..*-2];         # OUTPUT: Ā«(1 2 3)ā¤Ā»

Because Whatever-priming is a purely syntactic compiler transform, you will get no runtime priming of stored Whatever-stars into WhateverCodes.

my $x = *;
$x + 2;   # Not a closure, dies because it can't coerce $x to Numeric
CATCH { default { put .^name, ': ', .Str } };
# OUTPUT: Ā«X::Multi::NoMatch: Cannot resolve caller Numeric(Whatever: );
# none of these signatures match:ā¤
# (Mu:U \v: *%_)Ā»

The use cases for stored Whatever-stars involve those prime-exception cases mentioned above. For example, if you want an infinite series by default.

my $max    = potential-upper-limit() // *;
my $series = known-lower-limit() ... $max;

A stored * will also result in the generation of a WhateverCode in the specific case of smartmatch. Note that this is not actually the stored * which is being primed, but rather the * on the left-hand side.

my $constraint           = find-constraint() // *;
my $maybe-always-matcher = * ~~ $constraint;

If this hypothetical find-constraint were to have found no constraint, $maybe-always-matcher would evaluate to True for anything.

$maybe-always-matcher(555);      # True
$maybe-always-matcher(Any);      # True

HyperWhatever's functionality is similar to Whatever, except it refers to multiple values, instead of a single one.

Methods

method ACCEPTS

multi method ACCEPTS(Whatever:D: Mu $other)
    multi method ACCEPTS(Whatever:U: Mu $other)

If the invocant is an instance, always returns True. If the invocant is a type object, performs a typecheck.

say 42 ~~ (*);       # OUTPUT: Ā«Trueā¤Ā»
    say 42 ~~ Whatever;  # OUTPUT: Ā«Falseā¤Ā»

method Capture

method Capture()

Throws X::Cannot::Capture.

See Also

class int

Native integer

class Allomorph

Dual value number and string

class Any

Thing/object

class AST

Abstract representation of a piece of source code

class atomicint

Integer (native storage at the platform's atomic operation size)

class Block

Code object with its own lexical scope

class CallFrame

Captures the current frame state

class Code

Code object

class Collation

Encapsulates instructions about how strings should be sorted

class Compiler

Information related to the compiler that is being used

class Complex

Complex number

class ComplexStr

Dual value complex number and string

class Cool

Object that can be treated as both a string and number

class CurrentThreadScheduler

Scheduler that synchronously executes code on the current thread

class Date

Calendar date

class DateTime

Calendar date with time

class Distribution::Hash

Distribution::Hash

class Distribution::Locally

Distribution::Locally

class Distribution::Path

Distribution::Path

class Distribution::Resource

Every one of the resources installed with a distribution

class Duration

Length of time

class Encoding::Registry

Management of available encodings

class FatRat

Rational number (arbitrary-precision)

class ForeignCode

Rakudo-specific class that wraps around code in other languages (generally NQP)

class Format

Convert values to a string given a format specification

class Formatter

Produce Callable for given format specification

class HyperSeq

An object for performing batches of work in parallel with ordered output

class HyperWhatever

Placeholder for multiple unspecified values/arguments

class Instant

Specific moment in time

class Int

Integer (arbitrary-precision)

class IntStr

Dual value integer and string

class Junction

Logical superposition of values

class Label

Tagged location in the source code

class Lock::Async

A non-blocking, non-re-entrant, mutual exclusion lock

class Macro

Compile-time routine

class Method

Member function

class Mu

The root of the Raku type hierarchy.

class Nil

Absence of a value or a benign failure

class Num

Floating-point number

role Numeric

Number or object that can act as a number

class NumStr

Dual value floating-point number and string

class ObjAt

Unique identification for an object

class Parameter

Element of a Signature

class Perl

Perl related information

class Proxy

Item container with custom storage and retrieval

class RaceSeq

Performs batches of work in parallel without respecting original order.

class Raku

Raku related information

package RakuAST

Namespace for holding RakuAST related classes

class RakuAST::Doc::Block

Contains the information of a RakuDoc block

class RakuAST::Doc::Declarator

Contains the declarator docs of a RakuAST object

class RakuAST::Doc::Markup

Contains the information about RakuDoc markup

class RakuAST::Doc::Paragraph

Contains the information about a RakuDoc paragraph

class Rat

Rational number (limited-precision)

class RatStr

Dual value rational number and string

class Routine

Code object with its own lexical scope and return handling

class Routine::WrapHandle

Holds all information needed to unwrap a wrapped routine.

class Scalar

A mostly transparent container used for indirections

class Signature

Parameter list pattern

class Str

String of characters

class StrDistance

Contains the result of a string transformation.

class Sub

Subroutine

class Submethod

Member function that is not inherited by subclasses

class Telemetry

Collect performance state for analysis

class Telemetry::Instrument::Thread

Instrument for collecting Thread data

class Telemetry::Instrument::ThreadPool

Instrument for collecting ThreadPoolScheduler data

class Telemetry::Instrument::Usage

Instrument for collecting getrusage data

class Telemetry::Period

Performance data over a period

class Telemetry::Sampler

Telemetry instrument pod

Subset UInt

Unsigned integer (arbitrary-precision)

class ValueObjAt

Unique identification for value types

class Variable

Object representation of a variable for use in traits

class Version

Module version descriptor

class WhateverCode

Code object constructed by Whatever-priming

The Camelia image is copyright 2009 by Larry Wall. "Raku" is trademark of the Yet Another Society. All rights reserved.