Ghasem Kiani's Weblog

Notes about science, literature, society, and arts

2009-09-09

A Promise from God

بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيمِ

وَمَكَرُواْ مَكْراً وَمَكَرْنَا مَكْراً وَهُمْ لَا يَشْعُرُونَ

فَانظُرْ كَيْفَ كَانَ عَاقِبَةُ مَكْرِهِمْ أَنَّا دَمَّرْنَاهُمْ وَقَوْمَهُمْ أَجْمَعِينَ

فَتِلْكَ بُيُوتُهُمْ خَاوِيَةً بِمَا ظَلَمُواْ إِنَّ فِي ذَلِكَ لَآيَةً لِّقَوْمٍ يَعْلَمُونَ

وَأَنجَيْنَا الَّذِينَ آمَنُواْ وَكَانُواْ يَتَّقُونَ

النمل، 50-53

# Posted at 01:30 by Ghasem (1 comments)

2009-01-22

Recursion and Local Variables in JavaScript

Consider the following JavaScript code snippet.

function f(x)
{
 var s = "";
 if(x instanceof Array)
 {
  s += "[";
  for(i = 0; i < x.length; i++) s += f(x[i]);
  s += "]";
 }
 else
 {
  s += "(";
  s += x.toString();
  s += ")";
 }
 return s;
}
alert(f([1, [2, 3, 4], 5]));

If you put this code in an HTML page, you will see that it shows the following result:

[(1)[(2)(3)(4)]]

What's wrong with the code?

The problem is that we have not defined the variable i in the for loop as a local variable. When the function f calls itself recursively, the variable i will have a value from the inner call, and the rest of the loop will not be executed in the outer call.

Now, we add var i; before the loop.

function f(x)
{
 var s = "";
 if(x instanceof Array)
 {
  s += "[";
  var i;
  for(i = 0; i < x.length; i++) s += f(x[i]);
  s += "]";
 }
 else
 {
  s += "(";
  s += x.toString();
  s += ")";
 }
 return s;
}
alert(f([1, [2, 3, 4], 5]));

Here is the result:

[(1)[(2)(3)(4)](5)]

Whenever we use recursion in JavaScript, it is particularly important to take into account the scope of local variables.

تراجع و متغيرهاي محلي در جاوااسكريپت

قطعه‌ي كد جاوااسكريپت زير را در نظر بگيريد.

function f(x)
{
 var s = "";
 if(x instanceof Array)
 {
  s += "[";
  for(i = 0; i < x.length; i++) s += f(x[i]);
  s += "]";
 }
 else
 {
  s += "(";
  s += x.toString();
  s += ")";
 }
 return s;
}
alert(f([1, [2, 3, 4], 5]));

اگر اين كد را در يك صفحه‌ي HTML قرار دهيد، مي‌بينيد كه نتيجه‌ي زير را نشان مي‌دهد:

[(1)[(2)(3)(4)]]

مشكل اين متن برنامه در كجا است؟

مسئله آن است كه ما متغير i را در حلقه‌ي for به عنوان يك متغير محلي تعريف نكرده‌ايم. وقتي كه تابع f خودش را به صورت تراجعي فرا مي‌خواند، متغير i از فراخواني داخلي، داراي مقدار خواهد بود و بقيه‌ي حلقه در فراخواني خارجي اجرا نخواهد شد.

حالا يك سطر var i; قبل از حلقه اضافه مي‌كنيم.

function f(x)
{
 var s = "";
 if(x instanceof Array)
 {
  s += "[";
  var i;
  for(i = 0; i < x.length; i++) s += f(x[i]);
  s += "]";
 }
 else
 {
  s += "(";
  s += x.toString();
  s += ")";
 }
 return s;
}
alert(f([1, [2, 3, 4], 5]));

نتيجه از اين قرار است:

[(1)[(2)(3)(4)](5)]

هر گاه در جاوااسكريپت از تراجع استفاده مي‌كنيم، اين موضوع اهميت خاصي دارد كه به قلمرو متغيرهاي محلي توجه كنيم.

# Posted at 21:03 by Ghasem (2 comments)

2008-11-18

The Brass Verdict

The Brass Verdict by Michael Connelly

The Brass Verdict, by Michael Connelly, is an account of corruption and hypocrisy. Featuring both Harry Bosch and Mickey Haller, it is, to some extent, reminiscent of Personal Injuries, by Scott Turow. The name refers to the brass jacket of rounds shot from a German-made Mauser gun.

I have read all of the fiction books by Michael Connelly, and this seems to be the best so far. Before that, I read the Hot Mahogany, the latest Stone Barrington novel, by Stuart Woods. (Ironically, I have read almost all previous books featuring this character, but in reverse order. Can you believe it?) Stuart Woods is certainly a great author, but, in my opinion, Michael Connelly is a lot better. More and more, he succeeds in polishing and advancing the genre of noir detective fiction.

The overwhelming cliché in Harry Bosch novels is the corrupt police. The idea behind the Lincoln Lawyer was a true villain, a real and heinous evil being. Though I hate to write spoilers, suffice it to say that this new one is about corruption on another level of authority. My point is that this book refers to a very relevant topic considering the actual state of our society. I did relish this novel and I do recommend it to all readers interested in crime fiction.

Labels: , , ,

# Posted at 09:18 by Ghasem (2 comments)

2008-09-15

Musings on Writing

I am currently reading “The Bourne Sanction” by Eric Van Lustbader and Robert Ludlum. It is a really good book. I haven’t read the three previous Bourne installments, but I have watched their respective movies. I wished I had read those three books that have been written by the late Ludlum himself, so that I can do a better appraisal of the prose of this book. Nevertheless, it has a superb prose and I like it very much.

Thrillers like other kinds of literary work consist of several dimensions. One dimension is the element of suspense and plot. No objection to that. But the prose is important, as well. One of my favorite authors, who is a bestselling author in the thriller genre, does not enjoy a particular power in writing fluent prose. This I regret. He is my real favorite because of his school of thought and so on.

The importance of the element of balance cannot be overemphasized. I hate books laden with lengthy, descriptive passages which are of no avail to the main objective of the book. There are plenty of such compulsory writers, some of them even famous in literary circles. But for someone like me who is interested in good thriller books, the artistic element of the book must be in a delicate balance with its being a hilarious thriller.

The element of humor and the writer’s personality sometimes gets very outstanding and ruins the book to some extent. The mood and morality of the author should not be conspicuous in a fiction book. This is another place where balance plays an important role.

So much for musing in a field I have no expertise in. Today, I became 38. On to a better year I hope.

# Posted at 12:52 by Ghasem (0 comments)

2007-08-03

Harry Potter and the Deathly Hallows

Last week I finished reading the seventh book in the Harry Potter series, "Harry Potter and the Deathly Hallows", and it was a very pleasurable experience. Since I am not going to spoil your reading of the book, I don't make any remarks as to the plot of the book. Ever since the publication of previous volume of the saga, which I have translated into Persian and you can download it for free, I occasionally worried that the last volume may disappoint me. There were some loose ends in the previous tomes, which couldn't help but make me more anxious to read the last installment. Well, here it is-much better than I could ask for.

While I was reading the seventh book, I got a feeling that it was written in a more fluent language, with lesser use of "dictionary" and "strictly British" words. This makes its translation much simpler. A word of thanks is due to Ms. Rowling for this! Moreover, this volume, enjoying a coherent and compelling plot, is a real page-turner. The ending is almost as I wished it to be. Since I don't like to read fan fiction, I am looking forward to reading more books written by JK Rowling in the future.

The Persian translations that sprang into being all over the net immediately after the release of the book (even before its release in some instances) prevented me form considering this volume for translation. There are a lot of good books out there waiting to be translated (and to be read, I hope—though, sometimes, the lack of book reading in my country is disappointing!)…

«هري پاتر و يادگارهاي مرگ»

هفته‌ي گذشته كتاب هفتم مجموعه‌ي هري پاتر را، كه ترجمه‌ي پيشنهادي من براي عنوان آن «هري پاتر و يادگارهاي مرگ» است، خواندم و بايد بگويم كه كتاب بسيار خوبي بود. البته قصد ندارم به ماجراي داستان اشاره كنم تا لذت كساني را كه هنوز نخوانده‌اند، از بين نبرم. از زمان انتشار جلد قبلي، هميشه ترسم اين بود كه آخرين كتاب داستان خوبي نداشته باشد و توقعات زيادي را كه از هري پاتر در خوانندگان پيدا شده است، بر آورده نكند. علاوه بر اين، معماهاي حل نشده‌اي در جلد قبل مطرح شده بود كه اشتياق مرا براي خواندن جلد آخر بيشتر مي‌كرد. بالاخره كتاب منتشر شد و حتي از حد انتظار من هم بهتر بود.

در حين خواندن كتاب هفتم، احساس كردم كه اين جلد روان‌تر نوشته شده و كمتر از كلمات لغتنامه‌اي و «مطلقاً بريتانيايي» استفاده كرده است. به نظر من، در اين مورد بايد از خانم رولينگ سپاسگزار باشيم! به علاوه، اين جلد از داستاني همخوان و گيرا برخوردار است كه سبب مي‌شود كتاب را نتوان در حين خواندن به سادگي زمين گذاشت. پايان داستان تقريباً همان جوري است كه من آرزويش را داشتم. چون من از خواندن كتاب‌هاي هواداران (fan fiction) خوشم نمي‌آيد، اميدوارم در آينده نيز كتاب‌هاي بيشتري از جي.كي. رولينگ بخوانم.

از اولين لحظات انتشار كتاب هفتم (و در برخي از موارد، حتي از قبل از انتشار رسمي كتاب)، ترجمه‌هاي متعددي به زبان فارسي در اينترنت ظاهر شد، و همين امر سبب شد كه من حتي فكر ترجمه كردن اين جلد را به سرم راه ندهم. كتاب‌هاي خوب زيادي براي ترجمه هست (البته اميدوارم كه خواننده هم داشته باشد—بعضي وقت‌ها كم بودن كتابخواني در ايران خيلي آزارم مي‌دهد!)…

# Posted at 20:51 by Ghasem (0 comments)

2007-07-08

Harry Potter

متن كامل هري پاتر 6 ترجمه‌ي قاسم كياني مقدم

 

متن كامل هري پاتر 6 با عنوان «هري پاتر و پرنس نيمه‌اصيل» را مي‌توانيد از اينجا دريافت كنيد.

پس از رفتن به صفحه‌ي مذكور، روي لينك Download file كليك كنيد.

كتاب با فرمت PDF است و حجم آن 5,978 كيلوبايت است.

# Posted at 10:35 by Ghasem (0 comments)

2007-02-16

Thrillers

A Few Great Books

Next by Michael Crichton

Michael Crichton's "Next" is about a not-so-distant future when genetic engineering has encroached every aspect of our life. As usual, the author warns us about the uninhibited progress of science. I enjoyed this book much better than the "State of Fear". Like many of the novels by Crichton, the characters seem to be one-dimensional, almost soulless, but the events are very entertaining, and the science interspersed in the book is informative.

"Next" has a unique tinge of humor which I have not seen in other books by Crichton. In a certain part of the book, a company which has claimed ownership of a cell line derived from the cells of a patient's body, employs a bounty hunter to acquire another sample from the body of that patient or his progeny, claiming that the cells in their body also belongs to that company. It seems improbable that any jurisdiction may ever reach to such a ridiculous conclusion, but this is humorous anyway, and I think I can understand the logic behind it. Overall, this seems to be one of the best books by Michael Crichton. I recommend it to every reader interested in technothrillers.

The Lincoln Lawyer by Michael Connelly

Michael Connelly is my favorite author of crime and legal thrillers. I have read every book in the Harry Bosch series, and I have enjoyed all of them. "The Lincoln Lawyer" is a legal thriller, even better than many of his other books. This book features Mickey Haller, Harry's half-brother, who is a defense attorney. Haller used to think that the worst client for a defense attorney is an innocent client. But he encounters another kind of client who is much worse, a really evil man. The Lincoln Lawyer is the best book I have read for some time.

The Surgeon by Tess Gerritsen

Tess Gerritsen is another author who has used the theme of evil perps in her books. Her novels enjoy a robust balance of character development and page-turning plots. After reading The Surgeon and The Apprentice, I can't help but to start reading the third book in the Jane Rizzoli series, The Sinner. The problem is, I see a lot of true evilness in her books, but there is little sign of true righteousness. For one thing, Jane Rizzoli does a lot of attempt to prove herself, to get credit for the works she does. I do like real-looking characters, with a natural blend of strong and weak points. But I think there is some place for true virtue and good in her books. Rizzoli should have more valuable drives for her works than just "proving herself." Anyway, Gerritsen is a great author and has a great, useful blog which I usually read on a regular basis. And she has many other bestseller works which I plan to read in the near fututre. Maybe I'll change my mind after reading them.

چند كتاب خوب

بعدي اثر مايكل كرايتون

كتاب «بعدي» اثر مايكل كرايتون در باره‌ي آينده‌ي نه چندان دوري است كه در آن، مهندسي ژنتيك بر تمام جنبه‌هاي زندگي ما چنگ انداخته است. طبق معمول، مؤلف در اين كتاب در باره‌ي پيشرفت افسارگسيخته‌ي علم هشدار مي‌دهد. اين كتاب به نظر من بهتر از «وضعيت ترس» بود. البته، مانند خيلي از رمان‌هاي ديگر كرايتون، شخصيت‌ها يك‌بعدي و تقريباً بي‌روح به نظر مي‌رسند، ليكن رويدادها بسيار جذاب هستند، و نكات علمي پراكنده در لابلاي كتاب نيز آموزنده است.

كتاب «بعدي» با شوخ‌طبعي خاصي همراه است كه در كتاب‌هاي ديگر كرايتون به ندرت به چشم مي‌خورد. در يك جاي داستان، شركتي كه مالك يك رده‌ي سلولي به دست آمده از سلول‌هاي بدن يك بيمار شناخته شده است، افرادي را اجير مي‌كند كه مجدداً از بدن آن بيمار يا فرزندانش نمونه بگيرند، چون معتقد است سلول‌هاي موجود در بدن آنها نيز به آن شركت تعلق دارند. بعيد است كار دستگاه قضايي در آينده به دادن چنين حكم مضحكي بكشد، ولي به هر حال، اين قسمت داستان مفرح است و به گمانم مي‌توانم منطق نهفته در اين رويداد عجيب را درك كنم. روي هم رفته، به نظر مي‌رسد كه اين كتاب يكي از بهترين كتابهاي مايكل كرايتون است. من آن را به هر خواننده‌ي علاقه‌مند به داستان‌هاي علمي و فناوري توصيه مي‌كنم.

وكيل ليموزين‌سوار اثر مايكل كانلي

مايكل كانلي نويسنده‌ي مورد علاقه‌ي من در ژانر رمان‌هاي جنايي و حقوقي است. من تقريباً تمام كتاب‌هاي سري «هري بوش» را خوانده‌ام و برايم بسيار جذاب بودند. «وكيل ليموزين‌سوار» يكي از داستان‌هاي حقوقي او است كه حتي از كتاب‌هاي ديگرش هم بهتر است. در اين كتاب، با ميكي هالر، برادر ناتني هري بوش، كه يك وكيل مدافع است، ملاقات مي‌كنيم. هالر هميشه فكر مي‌كرد بدترين موكلي كه ممكن است به تورش بخورد، موكلي است كه واقعاً بي‌گناه باشد. ولي در اين كتاب با نوع بسيار بدتري از موكل رو به رو مي‌شود. فردي كه شرارت در نهاد او جاي گرفته است. «وكيل ليموزين‌سوار» بهترين كتابي است كه در اين اواخر خوانده‌ام.

جراح اثر تس گريتسن

تس گريتسن يكي ديگر از نويسندگاني است كه در كتاب‌هايش از بزهكاران شرور استفاده مي‌كند. رمان‌هاي او از تعادل خوبي بين شخصيت‌پردازي و وقايع پركشش برخوردار است. من اخيراً كتاب‌هاي «جراح» و «شاگرد» او را خواندم و بي‌صبرانه منتظر فرصتم تا خواندن سومين كتاب در سري «جين ريزولي» را، كه «گناهكار» نام دارد، آغاز كنم. مسئله اين است كه در كتاب‌هاي او شرارت واقعي زياد به چشم مي‌خورد، ولي كمتر اثري از خوبي مطلق يافت مي‌شود. مثلاً جين ريزولي هميشه در پي آن است كه موفقيت‌هاي كارآگاهي‌اش به نام كس ديگري ثبت نشود. البته من از كاراكترهاي واقعي كه تركيب متوازني از نقاط قوت و ضعف داشته باشند، بدم نمي‌آيد. ولي فكر مي‌كنم جاي خير مطلق در داستان‌هاي او تا حدودي خالي است. ريزولي بايد انگيزه‌هايي بالاتر از «اثبات كردن خود» براي كارهايش داشته باشد. در هر حال، گريتسن نويسنده‌ي بزرگي است و وبلاگ ارزشمندي نيز دارد كه من معمولاً به طور مرتب مطالب آن را مطالعه مي‌كنم. او كتاب‌هاي پرفروش متعدد ديگري نيز دارد كه تصميم دارم در آينده‌ي نزديك بخوانم. شايد آن موقع نظرم در باره‌ي آثار او عوض شود.

Labels: , ,

# Posted at 20:45 by Ghasem (0 comments)

Home | Archive
Copyright © 2003-2006, Ghasem Kiani