`
lobin
  • 浏览: 436552 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Regular Quasi-strings & Strong Quasi-string notation

 
阅读更多

 

> ((lambda (name age title) {my name: [name], age: [age] and title: [title]}) "adam" 22 "baba")
$43 = "my name: adam, age: 22 and title: baba"

 

> ((lambda (name age title) #{my name: [name], age: [age] and title: [title]}#) "adam" 22 "baba")
$44 = "my name: [name], age: [age] and title: [title]"

 

> ((lambda (name age title) #{my name: #[name]#, age: #[age]# and title: #[title]#}#) "adam" 22 "baba")
$45 = "my name: adam, age: 22 and title: baba"

C/C++实现类似效果:

#include <stdio.h>
#include <typeinfo.h>
#include <iostream>

using namespace std;

// Quasi-string & Strong Quasi-string
#define QUASI_STR(s)      #s

#define QUASI_STR_X2(op, s1, s2) \
  s1##op##s2

#define STRONG_QUASI_STR_X2(op, s1, s2) \
  #s1#op#s2

#define QUASI_STR2(s1, s2) \
  #s1#s2

#define STRONG_QUASI_STR2(s1, s2) \
  s1##s2

#define ADD(a, b) a + b

int main() 
{
  int i = 12;
  float j = 12.12f;
  cout << "typeid(int): " << typeid(12).name() << endl;
  //cout << "typeid(int): " << typeid(i).name() << endl;
  cout << "typeid(int): " << typeid(int).name() << endl;

  cout << "typeid(int): " << typeid(12.12f).name() << endl;
  //cout << "typeid(int): " << typeid(f).name() << endl;
  cout << "typeid(int): " << typeid(float).name() << endl;

  cout << "------------------------------------------" << endl;

  cout << ADD(i, i) << endl;

  cout << "------------------------------------------" << endl;

  cout << QUASI_STR(aaabbbccc) << endl;

  cout << QUASI_STR2(12, 12.12f) << endl;
  cout << STRONG_QUASI_STR2(12, 12.12f) << endl;

  cout << QUASI_STR2(i, 12.12f) << endl;
  //cout << STRONG_QUASI_STR2(i, 12.12f) << endl;

  int i12;
  cout << QUASI_STR2(i, 12) << endl;
  cout << STRONG_QUASI_STR2(i, 12) << endl;

  int ij;
  cout << QUASI_STR2(i, j) << endl;
  cout << STRONG_QUASI_STR2(i, j) << endl;

  return 0;
}

 

$ g++ -c cjtest.cpp -o cjtest.o
$ g++ cjtest.o -o cjtest
$ ./cjtest.exe
typeid(int): i
typeid(int): i
typeid(int): f
typeid(int): f
------------------------------------------
24
------------------------------------------
aaabbbccc
1212.12f
1212.12
i12.12f
i12
2282524
ij
1629105823

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics