Podcast #128: We chat with Kent C Dodds about why he loves React and discuss what life was like in the dark days before Git. Listen now.
3 I removed the things I fixed
source | link

I noticed two error in the given examples :

> let x = for (y in [2.3, 5.6]) y/5*6
> print product x
18.5472  # the example gives [2.76. 6.72]

And

> let b = [1, 2, 3]
> for (x in b) [x, x+1]
> print b
[1, 2, 3] #In the example the value of b changes, which is not the case

Here is the code of my interpreter :  

import sys,re
V={}
S=lambda m:re.sub(' +',';',m).split(';')
def P(t):print t;return []
def E(t): 
 if len(t)==1:return t[0]
 y=E(t[1:])
 return{'print':'P('+y+')','sum':'sum('+y+')','product':'reduce(lambda x,y:x*y'+y+',1)'}[t[0]]
def e(t):
 y=t[0]
 if y=='let':v=V[t[1]]=e(t[3:]);return v
 if y=='print':v=e(t[1:]);return P(v)
 if y=='sum':return sum(e(t[1:]))
 if y=='product':return reduce(lambda x,y:x*y,e(t[1:]),1)
 if y=='for':c=S(R(t[1][1:-1].replace('/',' ')));return eval('map(lambda %s:%s,%s)' % (c[0],E(t[2:]),str(e(c[2:]))))
 if y[0]=='[':v=V['input']=eval(re.sub('([a-zA-Z]+)',"V['\\1']",y));return v
 if re.match('[0-9]+',y):v=V['input']=eval(y);return v
 return V[y]
def R(s, u='[',e=']',r=''):
 m,b='',1
 for c in s:
  if b:
   m+=c
   if c==u:b=0
  else:
   m+=r if c==' 'else c
   if c==e:b=1
 return m
def i(s):
 try:e(S(R(R(s.replace('^','**'),'(',')','/'))))
 except ZeroDivisionError:print 'Division by zero!';sys.exit(1)
while 1:print '>',;i(raw_input())
import sys,re
V={}
S=lambda m:re.sub(' +',';',m).split(';')
def P(t):print t;return []
def E(t): 
 if len(t)==1:return t[0]
 y=E(t[1:])
 return{'print':'P('+y+')','sum':'sum('+y+')','product':'reduce(lambda x,y:x*y'+y+',1)'}[t[0]]
def e(t):
 y=t[0]
 if y=='let':v=V[t[1]]=e(t[3:]);return v
 if y=='print':v=e(t[1:]);return P(v)
 if y=='sum':return sum(e(t[1:]))
 if y=='product':return reduce(lambda x,y:x*y,e(t[1:]),1)
 if y=='for':c=S(R(t[1][1:-1].replace('/',' ')));return eval('map(lambda %s:%s,%s)' % (c[0],E(t[2:]),str(e(c[2:]))))
 if y[0]=='[':v=V['input']=eval(re.sub('([a-zA-Z]+)',"V['\\1']",y));return v
 if re.match('[0-9]+',y):v=V['input']=eval(y);return v
 return V[y]
def R(s, u='[',e=']',r=''):
 m,b='',1
 for c in s:
  if b:
   m+=c
   if c==u:b=0
  else:
   m+=r if c==' 'else c
   if c==e:b=1
 return m
def i(s):
 try:e(S(R(R(s.replace('^','**'),'(',')','/'))))
 except ZeroDivisionError:print 'Division by zero!';sys.exit(1)
while 1:print '>',;i(raw_input())

I noticed two error in the given examples :

> let x = for (y in [2.3, 5.6]) y/5*6
> print product x
18.5472  # the example gives [2.76. 6.72]

And

> let b = [1, 2, 3]
> for (x in b) [x, x+1]
> print b
[1, 2, 3] #In the example the value of b changes, which is not the case

Here is the code of my interpreter :  

import sys,re
V={}
S=lambda m:re.sub(' +',';',m).split(';')
def P(t):print t;return []
def E(t): 
 if len(t)==1:return t[0]
 y=E(t[1:])
 return{'print':'P('+y+')','sum':'sum('+y+')','product':'reduce(lambda x,y:x*y'+y+',1)'}[t[0]]
def e(t):
 y=t[0]
 if y=='let':v=V[t[1]]=e(t[3:]);return v
 if y=='print':v=e(t[1:]);return P(v)
 if y=='sum':return sum(e(t[1:]))
 if y=='product':return reduce(lambda x,y:x*y,e(t[1:]),1)
 if y=='for':c=S(R(t[1][1:-1].replace('/',' ')));return eval('map(lambda %s:%s,%s)' % (c[0],E(t[2:]),str(e(c[2:]))))
 if y[0]=='[':v=V['input']=eval(re.sub('([a-zA-Z]+)',"V['\\1']",y));return v
 if re.match('[0-9]+',y):v=V['input']=eval(y);return v
 return V[y]
def R(s, u='[',e=']',r=''):
 m,b='',1
 for c in s:
  if b:
   m+=c
   if c==u:b=0
  else:
   m+=r if c==' 'else c
   if c==e:b=1
 return m
def i(s):
 try:e(S(R(R(s.replace('^','**'),'(',')','/'))))
 except ZeroDivisionError:print 'Division by zero!';sys.exit(1)
while 1:print '>',;i(raw_input())

Here is the code of my interpreter :

import sys,re
V={}
S=lambda m:re.sub(' +',';',m).split(';')
def P(t):print t;return []
def E(t): 
 if len(t)==1:return t[0]
 y=E(t[1:])
 return{'print':'P('+y+')','sum':'sum('+y+')','product':'reduce(lambda x,y:x*y'+y+',1)'}[t[0]]
def e(t):
 y=t[0]
 if y=='let':v=V[t[1]]=e(t[3:]);return v
 if y=='print':v=e(t[1:]);return P(v)
 if y=='sum':return sum(e(t[1:]))
 if y=='product':return reduce(lambda x,y:x*y,e(t[1:]),1)
 if y=='for':c=S(R(t[1][1:-1].replace('/',' ')));return eval('map(lambda %s:%s,%s)' % (c[0],E(t[2:]),str(e(c[2:]))))
 if y[0]=='[':v=V['input']=eval(re.sub('([a-zA-Z]+)',"V['\\1']",y));return v
 if re.match('[0-9]+',y):v=V['input']=eval(y);return v
 return V[y]
def R(s, u='[',e=']',r=''):
 m,b='',1
 for c in s:
  if b:
   m+=c
   if c==u:b=0
  else:
   m+=r if c==' 'else c
   if c==e:b=1
 return m
def i(s):
 try:e(S(R(R(s.replace('^','**'),'(',')','/'))))
 except ZeroDivisionError:print 'Division by zero!';sys.exit(1)
while 1:print '>',;i(raw_input())
2 added 32 characters in body
source | link

Python 2.7, 979

I'm sure I could golf it further, but I don't see the point yet as I'm the only answer for the moment - I'm a bit lazy

I noticed two error in the given examples :

> let x = for (y in [2.3, 5.6]) y/5*6
> print product x
18.5472  # the example gives [2.76. 6.72]

And

> let b = [1, 2, 3]
> for (x in b) [x, x+1]
> print b
[1, 2, 3] #In the example the value of b changes, which is not the case

Here is the code of my interpreter : 

import sys,re
V={}
S=lambda m:re.sub(' +',';',m).split(';')
def P(t):print t;return []
def E(t): 
 if len(t)==1:return t[0]
 y=E(t[1:])
 return{'print':'P('+y+')','sum':'sum('+y+')','product':'reduce(lambda x,y:x*y'+y+',1)'}[t[0]]
def e(t):
 y=t[0]
 if y=='let':v=V[t[1]]=e(t[3:]);return v
 if y=='print':v=e(t[1:]);return P(v)
 if y=='sum':return sum(e(t[1:]))
 if y=='product':return reduce(lambda x,y:x*y,e(t[1:]),1)
 if y=='for':c=S(R(t[1][1:-1].replace('/',' ')));return eval('map(lambda %s:%s,%s)' % (c[0],E(t[2:]),str(e(c[2:]))))
 if y[0]=='[':v=V['input']=eval(re.sub('([a-zA-Z]+)',"V['\\1']",y));return v
 if re.match('[0-9]+',y):v=V['input']=eval(y);return v
 return V[y]
def R(s, u='[',e=']',r=''):
 m,b='',1
 for c in s:
  if b:
   m+=c
   if c==u:b=0
  else:
   m+=r if c==' 'else c
   if c==e:b=1
 return m
def i(s):
 try:e(S(R(R(s.replace('^','**'),'(',')','/'))))
 except ZeroDivisionError:print 'Division by zero!';sys.exit(1)
while 1:print '>',;i(raw_input())

You can play with it here

Python 2.7, 979

I'm sure I could golf it further, but I don't see the point yet as I'm the only answer for the moment - I'm a bit lazy

I noticed two error in the given examples :

> let x = for (y in [2.3, 5.6]) y/5*6
> print product x
18.5472  # the example gives [2.76. 6.72]

And

> let b = [1, 2, 3]
> for (x in b) [x, x+1]
> print b
[1, 2, 3] #In the example the value of b changes, which is not the case

Here is the code of my interpreter :

import sys,re
V={}
S=lambda m:re.sub(' +',';',m).split(';')
def P(t):print t;return []
def E(t): 
 if len(t)==1:return t[0]
 y=E(t[1:])
 return{'print':'P('+y+')','sum':'sum('+y+')','product':'reduce(lambda x,y:x*y'+y+',1)'}[t[0]]
def e(t):
 y=t[0]
 if y=='let':v=V[t[1]]=e(t[3:]);return v
 if y=='print':v=e(t[1:]);return P(v)
 if y=='sum':return sum(e(t[1:]))
 if y=='product':return reduce(lambda x,y:x*y,e(t[1:]),1)
 if y=='for':c=S(R(t[1][1:-1].replace('/',' ')));return eval('map(lambda %s:%s,%s)' % (c[0],E(t[2:]),str(e(c[2:]))))
 if y[0]=='[':v=V['input']=eval(re.sub('([a-zA-Z]+)',"V['\\1']",y));return v
 if re.match('[0-9]+',y):v=V['input']=eval(y);return v
 return V[y]
def R(s, u='[',e=']',r=''):
 m,b='',1
 for c in s:
  if b:
   m+=c
   if c==u:b=0
  else:
   m+=r if c==' 'else c
   if c==e:b=1
 return m
def i(s):
 try:e(S(R(R(s.replace('^','**'),'(',')','/'))))
 except ZeroDivisionError:print 'Division by zero!';sys.exit(1)
while 1:print '>',;i(raw_input())

Python 2.7, 979

I'm sure I could golf it further, but I don't see the point yet as I'm the only answer for the moment - I'm a bit lazy

I noticed two error in the given examples :

> let x = for (y in [2.3, 5.6]) y/5*6
> print product x
18.5472  # the example gives [2.76. 6.72]

And

> let b = [1, 2, 3]
> for (x in b) [x, x+1]
> print b
[1, 2, 3] #In the example the value of b changes, which is not the case

Here is the code of my interpreter : 

import sys,re
V={}
S=lambda m:re.sub(' +',';',m).split(';')
def P(t):print t;return []
def E(t): 
 if len(t)==1:return t[0]
 y=E(t[1:])
 return{'print':'P('+y+')','sum':'sum('+y+')','product':'reduce(lambda x,y:x*y'+y+',1)'}[t[0]]
def e(t):
 y=t[0]
 if y=='let':v=V[t[1]]=e(t[3:]);return v
 if y=='print':v=e(t[1:]);return P(v)
 if y=='sum':return sum(e(t[1:]))
 if y=='product':return reduce(lambda x,y:x*y,e(t[1:]),1)
 if y=='for':c=S(R(t[1][1:-1].replace('/',' ')));return eval('map(lambda %s:%s,%s)' % (c[0],E(t[2:]),str(e(c[2:]))))
 if y[0]=='[':v=V['input']=eval(re.sub('([a-zA-Z]+)',"V['\\1']",y));return v
 if re.match('[0-9]+',y):v=V['input']=eval(y);return v
 return V[y]
def R(s, u='[',e=']',r=''):
 m,b='',1
 for c in s:
  if b:
   m+=c
   if c==u:b=0
  else:
   m+=r if c==' 'else c
   if c==e:b=1
 return m
def i(s):
 try:e(S(R(R(s.replace('^','**'),'(',')','/'))))
 except ZeroDivisionError:print 'Division by zero!';sys.exit(1)
while 1:print '>',;i(raw_input())

You can play with it here

1
source | link

Python 2.7, 979

I'm sure I could golf it further, but I don't see the point yet as I'm the only answer for the moment - I'm a bit lazy

I noticed two error in the given examples :

> let x = for (y in [2.3, 5.6]) y/5*6
> print product x
18.5472  # the example gives [2.76. 6.72]

And

> let b = [1, 2, 3]
> for (x in b) [x, x+1]
> print b
[1, 2, 3] #In the example the value of b changes, which is not the case

Here is the code of my interpreter :

import sys,re
V={}
S=lambda m:re.sub(' +',';',m).split(';')
def P(t):print t;return []
def E(t): 
 if len(t)==1:return t[0]
 y=E(t[1:])
 return{'print':'P('+y+')','sum':'sum('+y+')','product':'reduce(lambda x,y:x*y'+y+',1)'}[t[0]]
def e(t):
 y=t[0]
 if y=='let':v=V[t[1]]=e(t[3:]);return v
 if y=='print':v=e(t[1:]);return P(v)
 if y=='sum':return sum(e(t[1:]))
 if y=='product':return reduce(lambda x,y:x*y,e(t[1:]),1)
 if y=='for':c=S(R(t[1][1:-1].replace('/',' ')));return eval('map(lambda %s:%s,%s)' % (c[0],E(t[2:]),str(e(c[2:]))))
 if y[0]=='[':v=V['input']=eval(re.sub('([a-zA-Z]+)',"V['\\1']",y));return v
 if re.match('[0-9]+',y):v=V['input']=eval(y);return v
 return V[y]
def R(s, u='[',e=']',r=''):
 m,b='',1
 for c in s:
  if b:
   m+=c
   if c==u:b=0
  else:
   m+=r if c==' 'else c
   if c==e:b=1
 return m
def i(s):
 try:e(S(R(R(s.replace('^','**'),'(',')','/'))))
 except ZeroDivisionError:print 'Division by zero!';sys.exit(1)
while 1:print '>',;i(raw_input())