How to define a New Maxima Function



Hello!
 
Is it possible/easy to define in MAXIMA a generic SYMBOLIC function of 
the following form?
 
F( x, (x11,x12,f1(x)), (x21,x22,f2(x), ... ) 
 
==
 
f1(x), if x in [x11,x12]
f2(x), if x in [x21,x22]
...
0, if x elsewhere
 
 
Example: F(x, (0,2,2*x), (4,6,4*x))
 
To deliver:
 
diff(F) 
==
2, at x=1
4, at x=5
0, at x=3
 
 
Thank you in advance for your input!
 
Best regards
Alex