Pages

Showing posts with label pascal. Show all posts
Showing posts with label pascal. Show all posts

Saturday, April 20, 2024

낯선 Rust에서 오래된 Object Pascal의 향기를 느끼다

요즘 새로운 프로그램을 만드는데, 이 참에 공부좀 해보자 해서 Rust로 만들어보고 있습니다.

아무래도 멘땅에 헤딩하다 보니까 고조할아버지 제삿날 종가집 시어머니급 잔소리를 늘어놓으며 사사건건 시시콜콜하게 간섭해대는 rust-analyzer와 싸우면서(?) 즐거운(?) 나날을 지내고 있습니다만...... 오늘 재미있는걸 하나 발견했습니다.

Rust에서는 이 구문을 오류로 보더군요.

이걸 수정하려면 이렇게 고쳐야 됩니다.

이 코드를 보니 예전 Object Pascal (Delphi) 시절이 생각나는군요. primitive type이 아니면 var 절에서 객체 변수를 선언한 뒤에 구현부에서 꼭 초기화를 시켜줘야 하고, 그렇지 않으면 바로 runtime error를 뻥뻥 토해냈는데, 구조가 완전히 똑같습니다. Rust도 마찬가지이긴 합니다만, 차이점이라면 메모리가 할당되지 않았다는걸 컴파일 타임에 발견해낼 수 있다는 정도일까요.

Pascal이란 언어는 자기 자신은 비주류인 주제에 온갖 잡다한(?) 언어들에게 무수한 영향을 끼치는군요. Java도 Python도 Javascript도 심지어는 Rust도 모두 다 Object Pascal의 구조를 일정수준 이상 차용해왔으니......

과거 해당 언어의 추종자로서, 아련한 기분이 듭니다.

See old Object Pascal from new Rust

Nowadays I'm working on a new application, and I thought it's a good chance to learn something new, I tried Rust.

As a newbie(or noob) in this area, I enjoy the time fighting against rust-analyzer that always-whining like Grouchy Smurf...... (lol) And today I found something interesting.

In Rust, the following is an error.

To fix, the first line should be changed like following.

Seeing the code reminds me of the good old days of Object Pascal (Delphi). If it's not an primitive type you've got to declare the variable in var clause and call constructor in implementation, or it'll emit runtime error. And Rust "inherited" the structure as it was, except for catching non-memory-assignment in compile time.

The programming language Pascal is a minor one as it is, it influences to too many other languages, like Java, Python, Javascript, and now Rust....... They all adopted at least some part of Object Pascal.

As a good follower of the language, I feel dim as I saw this.


Thursday, October 31, 2013

XMLlucination: 의사(pseudo) XML 해석기

XMLlucination은 XML 문서에 대한 의사(pseudo) 해석기입니다. XMLlucination은 노드를 찾고, 속성이나 노드 안의 raw text를 읽을 수 있습니다. 예. raw text입니다 - 텍스트 엘리먼트같은 것만 선택적으로 뽑아내는게 아니라, 노드 안에 있는 텍스트 전체를 뽑아내는 무식한 녀석입니다(……).

이 코드의 라이선스는 Lazarus의 라이선스 조건을 따릅니다. 기본적으로는 LGPL이나, 추가적으로 static link를 허용합니다.

간단한 사용법은 다음과 같습니다:

  1. 파일을 PChar 배열이나 String에 읽어들입니다.
  2. LocateNodePair()를 사용하여 TNodePair를 받습니다.
  3. GetAttributeValue()에 TNodePair.Open를 적용하여 속성값을 얻어냅니다.
  4. GetNodeValue()에 TNodePair 객체를 적용하면 node 안의 text를 얻을 수 있습니다.

아무쪼록 도움이 되셨으면 좋겠습니다. 즐거운 코딩 되세요!

2014년 4월 21일 추가:2013년 10월 31일에 등록된 원본 포스팅에서는 본 포스팅에 모든 소스코드를 공개하였으나,지금은 소스코드를 Google Drive의 파일 링크로 대체합니다. Uploading 당시 Tumblr의 오류로 추정되는 이상행위로 인해 소스코드가 여러모로 사용 불가능하게 등록되어 있더군요(따옴표의 유니코드 대체, ‘보다 작다’ 부등호 사인의 삭제 등).
이 문장을 클릭하시면 파일을 다운로드하실 수 있습니다.

XMLlucination: XML pseudo-parser

XMLlucination is a pseudo-parser for XML documents, in which you can locate nodes and read attributes or raw text between nodes. Yes. It is raw text - anything between nodes, not intelligently extract text elements only. :P

This code applies the same license terms of Lazarus, LGPL with additionally accepting static link.

Quick start guide:

  1. Load a file to array of PChar or String
  2. Use LocateNodePair() to get a TNodePair
  3. Use GetAttributeValue() with TNodePair.Open to search for a attribute value
  4. Use GetNodeValue() with TNodePair object
Hope you like it. Happy coding!

Edit at April 21th. 2014:In the original posting at Oct. 31. 2013, I opened the full source code here but now I replace the code with download link to Google Drive. I found out the source code is broken, which is expected to unexpected Tumblr behavior(replacing the quotation mark to unicode characters, deleting ‘less than’ sign accidentally, etc).

Click here to download the file.