Extending the python language : KM2 as a macro processor

Extending the python language : KM2 as a macro processor

The principle of notations is at the very heart of KM2 : expressing clearly ideas is key for knowledge management.

Using the SGH schemes, KM2 allows to build quickly a powerful macro preprocessor for Python.

Macro for characters

The example above shows that in a few lines of macros, we can use roman numbers for counting in python, which is quite unusual !

Another example is the possiblity to define local syntaxes, which allow mathematical writings to be used in a much clearer way than what is usually done in computer languages :

In general, KM2 uses a powerful search and generation engine to allow the production of texts, programms or new SGH schemes automatically.

Macro commmands for trees

Going further, suppose we have some instruction like code A:

print x

2 errors might occur :

  • x is not defined
  • x is not printable

so we would like to change the code to something like code B :

try :

print x

except :

print 'some error occured while doing "print x" '

pass

But the code becomes ugly ! ... and we may have many similar situations in our source.

So KM2 allows to define a macro M with an icon that embeds the code A, and generates automatically B .

unprotected code : print x

protected code :





要查看或添加评论,请登录

Laurent Gouzènes的更多文章

社区洞察

其他会员也浏览了