LPMuds.net
September 03, 2010, 11:22:21 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: This is the forum page. For the main LPMuds page, visit http://lpmuds.net
 
   Home   SITE FAQ INTERMUD DOWNLOADS LINKS Help Search Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: unification style pattern matching for LPC  (Read 1041 times)
silenus
BFF
***
Offline Offline

Posts: 102


View Profile
« on: September 05, 2008, 08:19:52 PM »

Hello,

While working on my driver project I have been considering possible "extensions" to the LPC language and sort of have a request for comments type document. The question is whether it would be meaningful to introduce unification style pattern matching in some form into LPC. This would in its most basic form result in the modification of two constructs which can be illustrate by the following code:

Code:
int factorial(int n)
{
    case 1: return 1;
    case n: return n*factorial(n-1);
}

switch(int n,string s)
{
   case 1, "silenus" : x = 1; break;
   case 1, "cratylus" : x = 2; break;
}


The idea is that this would involve mappings and arrays as well allowing for deep pattern matching i.e. something like

Code:
case ({x,y,({z,w})) : <use the variables here>

which would match something like ({1,2, ({3,4}) with x = 1, y = 2, z = 3 & w = 4 and so on. This could would also work with mappings where the keys would be considered as addresses and the values again pattern matched in this fashion. This could be made to apply to structs/classes in the same fashion.

I can already see some potential applications for this and a couple extensions which could make them more useful- but I am curious if anyone sees any promise in the basic idea of porting this notion from ML/Haskell etc into LPC.

Thanks in advance,

Silenus.
Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!