News for hackers. Stuff that matters.
Re:The visitor pattern is essentially the same thing as Chur... by h_anna_h on Thursday February 04, 2021 @03:26PM (#26029394)
Here you go

  import math
  
  def Circle(x, y, r):
      return (lambda d : d['visitCircle'](x, y, r))
  
  def Rectangle(x, y, w, h):
      return (lambda d : d['visitRectangle'](x, y, w, h))
  
  def area(shape):
      return shape({
          'visitCircle':    lambda x, y, r    : math.pi * r * r,
          'visitRectangle': lambda x, y, w, h : w * h
      })
  
  exampleCircle = Circle(2, 1.4, 4.5)
  exampleRectangle = Rectangle(1.3, 3.1, 10.3, 7.7)
  
  print(area(exampleCircle))
  print(area(exampleRectangle))
  # 63.61725123519331
  # 79.31
Re:The visitor pattern is essentially the same thing as Chur... by mdoms on Thursday February 04, 2021 @04:45PM (#26030159)
At this point I have to believe you functional programming guys are just taking the piss.
Re:The visitor pattern is essentially the same thing as Chur... by h_anna_h on Thursday February 04, 2021 @06:45PM (#26031162)
What do you mean? This solves the issue that you mentioned. I am not really a "functional programming guy" myself.
Re:The visitor pattern is essentially the same thing as Chur... by mdoms on Thursday February 04, 2021 @07:23PM (#26031457)
Yes it solves the problem while introducing a hard dependency from a shape to some stringly typed hashmap from who-knows-where.
Re:The visitor pattern is essentially the same thing as Chur... by h_anna_h on Saturday February 06, 2021 @05:22AM (#26045596)
Not really sure what "stringly typed" means. This is just the effect of trying this trick in python.