A set is an unordered collection of objects that contains no duplicates.

Mimics
Inactive cells
Active cells
Specs
Inactive cells (details)
kind = "Set"
Active cells (details)
+(otherSet)

returns a new set that contains the receivers elements and the elements of the set sent in as the argument.

Set +
  • - should add two sets [ show source ]
    (set(1, 2) +(set(1, 3))) should ==(set(1, 2, 3)) 
    
    
  • - should validate type of argument [ show source ]
    fn(set(2) +(3)) should signal(Condition Error Type IncorrectType) 
    
    
  • - should validate type of receiver [ show source ]
    Set should checkReceiverTypeOn(:("+"), set(2)) 
    
    
<<(value)

Adds the argument to this set, if it's not already in the set. Returns the set after adding the object.

Set <<
  • - should add an element that isn't part of the set already [ show source ]
    x = set(1) 
    x <<(2) 
    x should ==(set(1, 2)) 
    
    
  • - should not add an element that is part of the set already [ show source ]
    x = set(1, 2, 3) 
    x <<(2) 
    x should ==(set(1, 2, 3)) 
    
    
  • - should return the set after adding [ show source ]
    x = set(1) 
    (x <<(2)) should be same(x) 
    
    
  • - should validate type of receiver [ show source ]
    Set should checkReceiverTypeOn(:("<<"), 2) 
    
    
==(other)

returns true if the left hand side set is equal to the right hand side set.

Set ==
  • - should return false when sent an argument that is not a set [ show source ]
    set should not ==(1) 
    set(1) should not ==(1) 
    set(1, 2, 3) should not ==("foo") 
    set should not ==(fn([])) 
    
    
  • - should return true for two empty sets [ show source ]
    x = set 
    x should ==(x) 
    set should ==(set) 
    
    
  • - should return true for two empty sets where one has a new cell [ show source ]
    x = set 
    y = set 
    x blarg = 12 
    x should ==(y) 
    
    
  • - should return false when the two sets have an element of different types [ show source ]
    set(1) should not ==(set("1")) 
    set(1, 2, 3) should not ==(set("1", "2", "3")) 
    
    
  • - should return false when the two sets have different size [ show source ]
    set(1) should not ==(set) 
    set(1) should not ==(set(1, 2, 3)) 
    
    
  • - should return true if the elements in the set are the same [ show source ]
    set(1) should ==(set(1)) 
    set("1") should ==(set("1")) 
    set(1, 2, 3, 4, 5, 6, 7) should ==(set(1, 2, 3, 4, 5, 6, 7)) 
    set(1, 1, 1, 1, 1, 1, 2, 3, 4, 5, 6, 7) should ==(set(1, 2, 3, 4, 5, 6, 7)) 
    set(1, 2, 3, 4, 5, 6, 7) should ==(set(1, 2, 3, 5, 4, 6, 7)) 
    
    
===(other)

nil

method(other, 
  if(self same?(
      []), 
    Reflector other:mimics?(cell(:other), 
      []), 
    bind(rescue(Condition Error, fn(c, false)), 
      self include?(
        other))))
Set ===
  • - should return false for something not in the set [ show source ]
    (set ===(:foo)) should be false 
    (set(1) ===(2)) should be false 
    (set(1, :foo, "bar") ===(2)) should be false 
    
    
  • - should return true for something in the set [ show source ]
    (set(:foo) ===(:foo)) should be true 
    (set(1, 2) ===(2)) should be true 
    (set(2, 1, :foo, "bar") ===(2)) should be true 
    
    
  • - should return true when called against Set and the other is a set [ show source ]
    (Set ===(Set)) should be true 
    (Set ===(set)) should be true 
    (Set ===(set(1, 2, 3))) should be true 
    (Set ===(set(:foo))) should be true 
    
    
  • - should return true when called against Set and the other is not a set [ show source ]
    (Set ===([])) should be false 
    (Set ===(1 ..(5))) should be false 
    (Set ===(:foo)) should be false 
    
    
?&(...)

if this set is non-empty, returns the result of evaluating the argument, otherwise returns the set

macro(
  argCount = call arguments length 
  cond(
    argCount ==(
      1), 
    
    theCode = call arguments [](
        0) 
    
    unless(empty?, 
      call argAt(0), 
      self), 
    error!(Condition Error Invocation NoMatch, message: call message, context: call currentContext)) 
  )
Set ?&
  • - should just return itself if empty [ show source ]
    (set ?&(42)) should ==(set) 
    (set ?&([](1, 2, 3))) should ==(set) 
    
    
  • - should return the result of evaluating the code if non-empty [ show source ]
    set(1) ?&(10) should ==(10) 
    set(1, 2, 3) ?&(20) should ==(20) 
    x = set(1, 2) 
    x ?&([](1, 2, 3)) should ==([](1, 2, 3)) 
    
    
?|(...)

if this set is empty, returns the result of evaluating the argument, otherwise returns the set

macro(
  argCount = call arguments length 
  cond(
    argCount ==(
      1), 
    
    theCode = call arguments [](
        0) 
    
    if(empty?, 
      call argAt(0), 
      self), 
    error!(Condition Error Invocation NoMatch, message: call message, context: call currentContext)) 
  )
Set ?|
  • - should just return itself if not empty [ show source ]
    set(1) ?|(x /(0)) should ==(set(1)) 
    set(1, 2, 3) ?|(x /(0)) should ==(set(1, 2, 3)) 
    x = set(1, 2) 
    x ?|(blarg) should be same(x) 
    
    
  • - should return the result of evaluating the code if empty [ show source ]
    set ?|(42) should ==(42) 
    set ?|([](1, 2, 3)) should ==([](1, 2, 3)) 
    
    
each([indexOrArgOrCode] nil, [argOrCode] nil, [code] nil)

takes either one, two or three arguments. if one argument is given, it should be a message chain that will be sent to each object in the set. the result will be thrown away. if two arguments are given, the first is an unevaluated name that will be set to each of the values in the set in succession, and then the second argument will be evaluated in a scope with that argument in it. if three arguments is given, the first one is an unevaluated name that will be set to the index of each element, and the other two arguments are the name of the argument for the value, and the actual code. the code will evaluate in a lexical context, and if the argument name is available outside the context, it will be shadowed. the method will return the set. the iteration order is not defined.

Set each
  • - should return a seq when given no arguments [ show source ]
    x = set each 
    x should mimic(Sequence) 
    
    
  • - should not do anything for an empty set [ show source ]
    x = 0 
    set each(++(x)) 
    x should ==(0) 
    
    
  • - should be possible to just give it a message chain, that will be invoked on each object [ show source ]
    Ground y = [] 
    Ground x_set_spec1 = method(Ground y <<(self)) 
    set(1, 2, 3) each(x_set_spec1) 
    Ground y sort should ==([](1, 2, 3)) 
    x = 0 
    set(1, 2, 3) each(nil 
      ++(x)) 
    x should ==(3) 
    
    
  • - should be possible to give it an argument name, and code [ show source ]
    y = [] 
    set(1, 2, 3) each(x, y <<(x)) 
    y sort should ==([](1, 2, 3)) 
    
    
  • - should return the object [ show source ]
    y = set(1, 2, 3) 
    (y each(x, x)) should ==(y) 
    
    
  • - should be possible to give it an extra argument to get the index [ show source ]
    y = [] 
    set(1, 2, 3, 4) each(i, x, y <<(i)) 
    y should ==([](0, 1, 2, 3)) 
    
    
  • - should establish a lexical context when invoking the methods. this context will be the same for all invocations. [ show source ]
    set(1, 2, 3) each(x_set_spec, blarg_set_spec = 32) 
    cell?(:x_set_spec) should be false 
    cell?(:blarg_set_spec) should be false 
    x = 14 
    set(1, 2, 3) each(x, blarg = 32) 
    x should ==(14) 
    
    
  • - should validate type of receiver [ show source ]
    Set should checkReceiverTypeOn(:each, "foo") 
    
    
empty?()

returns true if this set is empty, false otherwise

Set empty?
  • - should return true for an empty set [ show source ]
    x = set 
    x empty? should be true 
    
    
  • - should return false for an non empty set [ show source ]
    x = set(1) 
    x empty? should be false 
    x = set("abc", "cde") 
    x empty? should be false 
    
    
  • - should validate type of receiver [ show source ]
    Set should checkReceiverTypeOn(:empty?) 
    
    
hash()

returns a hash for the set

Set hash
  • - should return the same number for equal sets [ show source ]
    set hash should ==(set hash) 
    x = set(1) 
    y = set 
    y <<(1) 
    set(1, 2, 1) hash should ==(set(2, 2, 2, 2, 1) hash) 
    x hash should ==(y hash) 
    x hash should not ==(set hash) 
    
    
  • - should return different numbers for different sets [ show source ]
    set(1) hash should not ==(set("1") hash) 
    set hash should not ==(set(1) hash) 
    set(1) hash should not ==(set hash) 
    
    
  • - should do the computation using recursive applications of hash [ show source ]
    x = Origin mimic 
    y = Origin mimic 
    set(x) hash should not ==(set(y) hash) 
    x hash = method(42) 
    y hash = method(42) 
    set(x) hash should ==(set(y) hash) 
    
    
ifEmpty(...)

if this set is empty, returns the result of evaluating the argument, otherwise returns the set

macro(
  argCount = call arguments length 
  cond(
    argCount ==(
      1), 
    
    theCode = call arguments [](
        0) 
    
    if(empty?, 
      call argAt(0), 
      self), 
    error!(Condition Error Invocation NoMatch, message: call message, context: call currentContext)) 
  )
Set ifEmpty
  • - should just return itself if not empty [ show source ]
    set(1) ifEmpty(x /(0)) should ==(set(1)) 
    set(1, 2, 3) ifEmpty(x /(0)) should ==(set(1, 2, 3)) 
    x = set(1, 2) 
    x ifEmpty(blarg) should be same(x) 
    
    
  • - should return the result of evaluating the code if empty [ show source ]
    set ifEmpty(42) should ==(42) 
    set ifEmpty([](1, 2, 3)) should ==([](1, 2, 3)) 
    
    
include?(object)

returns true if the receiver includes the evaluated argument, otherwise false

Set include?
  • - should match something in the set [ show source ]
    set(1) include?(1) should be true 
    set(1, 2) include?(2) should be true 
    set(2, 3, 1) include?(3) should be true 
    set("foo", "bar") include?("foo") should be true 
    
    
  • - should not match something not in the set [ show source ]
    set(1) include?(2) should be false 
    set(1, 2) include?(3) should be false 
    set(2, 3, 1) include?(:bar) should be false 
    set("foo", "bar") include?(:bar) should be false 
    
    
  • - should validate type of receiver [ show source ]
    Set should checkReceiverTypeOn(:include?, 42) 
    
    
inspect()

Returns a text inspection of the object

Set inspect
  • - should return something inside of a call to set [ show source ]
    set inspect should ==("set()") 
    set inspect should ==("set()") 
    set(1) inspect should ==("set(1)") 
    
    
  • - should use inspect format for things inside [ show source ]
    set(method(foo bar baz)) inspect should ==("set(method(foo bar baz))") 
    
    
  • - should return all the elements separated by commas [ show source ]
    val = set(1, 2, 2, 2) inspect 
    (val ==("set(1, 2)")) ||((val ==("set(2, 1)")) should be true) 
    
    
  • - should validate type of receiver [ show source ]
    Set should checkReceiverTypeOn(:inspect) 
    
    
notice()

Returns a brief text inspection of the object

Set notice
  • - should return something inside of a call to set [ show source ]
    set notice should ==("set()") 
    set notice should ==("set()") 
    set(1) notice should ==("set(1)") 
    
    
  • - should use notice format for things inside [ show source ]
    set(method(foo bar baz)) notice should ==("set(method(...))") 
    
    
  • - should return all the elements separated by commas [ show source ]
    val = set(1, 2, 2, 2) notice 
    (val ==("set(1, 2)")) ||((val ==("set(2, 1)")) should be true) 
    
    
  • - should validate type of receiver [ show source ]
    Set should checkReceiverTypeOn(:notice) 
    
    
remove!(value)

Removes the argument from the set, if it's in the set. Returns the set after removing the object.

Set remove!
  • - should remove entry from set [ show source ]
    set(1, 2) remove!(1) should ==(set(2)) 
    
    
  • - should validate type of receiver [ show source ]
    Set should checkReceiverTypeOn(:remove!, 42) 
    
    
seq()

returns a new sequence to iterate over this set

Set seq
  • - should return false when calling next? on a seq from an empty set [ show source ]
    set seq next? should be false 
    
    
  • - should return a Sequence [ show source ]
    set(1) seq should mimic(Sequence) 
    
    
  • - should return an object that yields all objects in the set [ show source ]
    all = [] 
    ss = set(42, 45, 6443) seq 
    all <<(ss next) 
    all <<(ss next) 
    all <<(ss next) 
    ss next? should be false 
    all sort should ==([](42, 45, 6443)) 
    
    
withIdentitySemantics!()

Converts this set to use identity semantics, and then returns it.

Set withIdentitySemantics!
  • - should validate type of receiver [ show source ]
    Set should checkReceiverTypeOn(:withIdentitySemantics!) 
    
    
?(element)

returns true if the argument is in the set

method(element, 
  include?(element))
Set ?
  • - should return false if the thing is not in the set [ show source ]
    (set ?(1)) should be false 
    (set(1, 2, 3) ?(42)) should be false 
    (set(1, 2, 3) ?(set(1))) should be false 
    
    
  • - should return true if the thing is in the set [ show source ]
    (set(1) ?(1)) should be true 
    (set(set(1)) ?(set(1))) should be true 
    (set(1, 2, 42, 3) ?(42)) should be true 
    
    
  • - should be possible to call in canonical form [ show source ]
    set(1) ?(1) should be true 
    
    
?(element)

returns false if the argument is in the set

method(element, 
  !(include?(element)))
Set ?
  • - should return true if the thing is not in the set [ show source ]
    (set ?(1)) should be true 
    (set(1, 2, 3) ?(42)) should be true 
    (set(1, 2, 3) ?(set(1))) should be true 
    
    
  • - should return false if the thing is in the set [ show source ]
    (set(1) ?(1)) should be false 
    (set(set(1)) ?(set(1))) should be false 
    (set(1, 2, 42, 3) ?(42)) should be false 
    
    
  • - should be possible to call in canonical form [ show source ]
    set(1) ?(42) should be true 
    
    
?(otherSet)

returns a new set that is the intersection of the receiver and the argument.

Set ?
  • - should return the empty set if one of the sets is empty [ show source ]
    (set ?(set(1, 3))) should ==(set) 
    (set(1, 3) ?(set)) should ==(set) 
    
    
  • - should return the empty set if there is no intersection [ show source ]
    (set ?(set)) should ==(set) 
    (set(1) ?(set(2))) should ==(set) 
    (set(5, 6) ?(set(1, 3))) should ==(set) 
    
    
  • - should return a set of all the things in both sets [ show source ]
    (set(1, 2) ?(set(2, 3))) should ==(set(2)) 
    (set(1, 2, 3, 4) ?(set(1, 2, 3, 4, 5))) should ==(set(1, 2, 3, 4)) 
    
    
?(other)

returns a new set that is the set-theoretic union of this set and the argument set

method(other, 
  self +(other))
Set ?
  • - should add two sets [ show source ]
    (set ?(set(1, 3))) should ==(set(1, 3)) 
    (set ?(set)) should ==(set) 
    (set(1, 2) ?(set(1, 3))) should ==(set(1, 2, 3)) 
    
    
?(otherSet)

returns true if this set is a proper subset of the argument set

Set ?
  • - should always return true when sent to an empty set except if both sets are empty [ show source ]
    (set ?(set(1))) should be true 
    (set ?(set("42", "55"))) should be true 
    
    
  • - should return true if all the elements are within the other set [ show source ]
    (set(2) ?(set(1, 2, 3))) should be true 
    (set("bar", "foo") ?(set("foo", "bar", "quux"))) should be true 
    
    
  • - should return false if the sets are the same [ show source ]
    x = set(42, 55, 18) 
    (x ?(x)) should be false 
    
    
  • - should return false if the sets are equal [ show source ]
    (set ?(set)) should be false 
    (set(42, 55, 18) ?(set(42, 55, 18))) should be false 
    
    
  • - should return false if at least one element isn't in the argument set [ show source ]
    (set(1) ?(set)) should be false 
    (set(1) ?(set(2))) should be false 
    (set(1, 2, 3) ?(set(1, 2))) should be false 
    
    
?(otherSet)

returns true if this set is a proper superset of the argument set

Set ?
  • - should always return true when the argument is the empty set, except if both sets are empty [ show source ]
    (set(1) ?(set)) should be true 
    (set("42", "55") ?(set)) should be true 
    
    
  • - should return true if all the elements are within the other set [ show source ]
    (set(1, 2, 3) ?(set(2))) should be true 
    (set("bar", "foo", "quux") ?(set("foo", "bar"))) should be true 
    
    
  • - should return false if the sets are the same [ show source ]
    x = set(42, 55, 18) 
    (x ?(x)) should be false 
    
    
  • - should return false if the sets are equal [ show source ]
    (set ?(set)) should be false 
    (set(42, 55, 18) ?(set(42, 55, 18))) should be false 
    
    
  • - should return false if at least one element isn't in the argument set [ show source ]
    (set ?(set(1))) should be false 
    (set(2) ?(set(1))) should be false 
    (set(1, 2) ?(set(1, 2, 3))) should be false 
    
    
?(otherSet)

returns true if this set is a subset of the argument set

Set ?
  • - should always return true when sent to an empty set [ show source ]
    (set ?(set)) should be true 
    (set ?(set(1))) should be true 
    (set ?(set("42", "55"))) should be true 
    
    
  • - should return true if all the elements are within the other set [ show source ]
    (set(2) ?(set(1, 2, 3))) should be true 
    (set("bar", "foo") ?(set("foo", "bar", "quux"))) should be true 
    
    
  • - should return true if the sets are the same [ show source ]
    x = set(42, 55, 18) 
    (x ?(x)) should be true 
    
    
  • - should return true if the sets are equal [ show source ]
    (set(42, 55, 18) ?(set(42, 55, 18))) should be true 
    
    
  • - should return false if at least one element isn't in the argument set [ show source ]
    (set(1) ?(set)) should be false 
    (set(1) ?(set(2))) should be false 
    (set(1, 2, 3) ?(set(1, 2))) should be false 
    
    
?(otherSet)

returns true if this set is a superset of the argument set

Set ?
  • - should always return true when the argument is an empty set [ show source ]
    (set ?(set)) should be true 
    (set(1) ?(set)) should be true 
    (set("42", "55") ?(set)) should be true 
    
    
  • - should return true if all the elements are within the other set [ show source ]
    (set(1, 2, 3) ?(set(2))) should be true 
    (set("bar", "foo", "quux") ?(set("foo", "bar"))) should be true 
    
    
  • - should return true if the sets are the same [ show source ]
    x = set(42, 55, 18) 
    (x ?(x)) should be true 
    
    
  • - should return true if the sets are equal [ show source ]
    (set(42, 55, 18) ?(set(42, 55, 18))) should be true 
    
    
  • - should return false if at least one element isn't in the argument set [ show source ]
    (set ?(set(1))) should be false 
    (set(2) ?(set(1))) should be false 
    (set(1, 2) ?(set(1, 2, 3))) should be false