<commit_before>import spryvm, sequtils

# An executable Spry polymorphic function
type
  # nodes hold Funk instances
  PolyMeth* = ref object of Meth

proc newPolyMeth*(funks: Blok, parent: Activation): Funk =
  PolyMeth(nodes: funks.nodes, parent: parent)

proc polymeth*(funks: Blok, spry: Interpreter): Node =
  newPolyMeth(funks, spry.currentActivation)

method `$`*(self: PolyMeth): string =
  return "polymethod [" & $self.nodes & "]"

method eval(self: PolyMeth, spry: Interpreter): Node =
  let receiver = evalArgInfix(spry)
  if receiver.isNil:
    return spry.nilVal
  let tags = receiver.tags
  if tags.isNil:
    return spry.nilVal
  let tagNodes = tags.nodes
  if tagNodes.isNil:
    return spry.nilVal
  for n in self.nodes:
    let fun = Funk(n)
    if any(tagNodes, proc (x: Node): bool = return fun.tags.nodes.contains(x)):
      return fun.eval(spry)
  return spry.nilVal

# Spry OO module
proc addOO*(spry: Interpreter) =<commit_msg>OO tweaks<commit_after>import spryvm, sequtils

# An executable Spry polymorphic function
type
  # nodes hold Funk instances
  PolyMeth* = ref object of Meth

proc newPolyMeth*(methods: Blok, parent: Activation): Funk =
  PolyMeth(nodes: methods.nodes, parent: parent)

proc polymeth*(methods: Blok, spry: Interpreter): Node =
  newPolyMeth(methods, spry.currentActivation)

method `$`*(self: PolyMeth): string =
  return "polymethod [" & $self.nodes & "]"

method eval*(self: PolyMeth, spry: Interpreter): Node =
  let receiver = evalArgInfix(spry)
  if receiver.isNil:
    return spry.nilVal
  let tags = receiver.tags
  if tags.isNil:
    return spry.nilVal
  let nodeTags = tags.nodes
  if nodeTags.isNil:
    return spry.nilVal
  for n in self.nodes:
    let funTags = Funk(n).tags.nodes
    for nt in nodeTags:
      if funTags.contains(nt):
        return Funk(n).eval(spry)
    #if any(nodeTags, proc (x: Node): bool = return fun.tags.nodes.contains(x)):
    #  return fun.eval(spry)
  return spry.nilVal

# Spry OO module
proc addOO*(spry: Interpreter) =
{'fraction_non_alphanumeric': 0.11166253101736973, 'fraction_numerical': 0.0, 'mean_word_length': 3.9655172413793105, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '200629', 'n_tokens_mistral': 720, 'n_tokens_neox': 701, 'n_words': 199}