misc-extensions-cvs
Threads by month
- ----- 2026 -----
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- 3 discussions
[misc-extensions-cvs] Is Israel a democracy? -- The problem with intellectually insecure whites -- Should Christians Support Israeli Terrorism in Gaza?
by Lawrence Auster 23 Jan '09
by Lawrence Auster 23 Jan '09
23 Jan '09
The Jewish State of Israel has no constitution, nor does it name its borders. Israel's hidden constitution is Judaism. Israel's undeclared borders range from the Nile to the Euphrates rivers. Israel's desired jurisdiction extends over the entire Earth.
It could not be more clear that the Jewish State follows a foreign policy which obeys Jewish Law as iterated in the Hebrew Bible, the Talmud, Maimonedes, the Cabalah, and the many commentaries and refinements of same. The Jews are genociding the native inhabitants of Palestine, just as their religion advises, and because
their religion teaches them to do so. They treat non-Jews as if non-humans, just as their religion requires them to do. They make perpetual war on every nation on Earth, just as their genocidal Jewish God has instructed.
The Jews of Israel are simply being Jews. Jews are an existential threat to the human race.
Israel contains one third of the Jews of the World. It is not some aberration of the Jewish spirit, but the condensation and concentration of the perverse Jewish mentality, which malady also pervades the remaining two thirds of Jewry, who almost unanimously support the Jewish State, and who certainly do unanimously support
the Jewish People and its consistent and constant crimes against the human race. Israel is Jewry and the danger of Israel is the danger of the Jewish People to all others, as the Jews have demonstrated each and every day of their existence.
The Jews, the entire Jewish People of 15 million, will not relent until they have wiped out all non-Jews in "Greater Israel". They will not stop destroying all other cultures, nations, religions, ethnicities, races, competition, etc. until they are either stopped, or succeed in their ancient quest to destroy the human race.
What Israel is doing is not some reaction to outside forces, nor was the formation of Israel a response to the Holocaust. Israel is simply following the plan laid out in the Jews' religious texts. The Jews have openly planned to take Palestine and genocide the native population of Palestine for some 2,500 years before the
Holocaust. The Jews have openly complained that "anti-Semitism" is a threat that gives them the right to genocide the Palestinians, not merely since the advent of Nazism, but for some 2,500 years.
The Jewish religion is the Constitution of the Jewish State of Israel, and, to a greater or lesser extent, the constitution of the nature of every Jew alive. The borders of Israel are the range the Jew roams over the entire World. The perverse Jewish mentality is inbred by a Jew's exposure to his parents and to his community. Judaism
passes in the spit and slobber of Jewish mother telling her Jewish child that he is a "Jew", as much as Judaism passes in the poison and pain of a Talmudic tractate. The secular Jews did not suddenly come to life after the Enlightenment and the Jewish Reformation a body of vampires that appeared ex nihilo, in vacuo, mostly
atheistical and undetached from formally practiced Judaism. Judaism is the Jew. It is a mindset that transcends and supercedes religion. It is a belief set, a way of life, a perception of one's self and one's relation to the World that makes a Jew, a Jew, and a danger to all of humanity.
In fact, the religious shell of Judaism is like the stretched and infected skin of a lycanthropic pustule. When you lance it to cure the infection, the virus only becomes more contagious and spills directly on the non-Jew.
The secular Jew is a deliberate product of the hyper-religious Jew, a monster created out of the hewed corpses of the fanatically religious Jew, a Golem which is conjured up to enter the World of the non-Jew and poison its blood, and boil its brain with a rabid lunacy that bites and spreads, until the infected community feeds on
itself and fills the fields with rotting bloating bodies, where once human beings tilled the soil and tended to their families. The religious Jew created the secular Jew as an army of Esthers who seduce with open thighs, broad smiles, and a Siren call that lures in the non-Jew to cast his skull upon the jagged rocks and color the seas
with his blood, sickened and blinded by the venereal disease of Judaism in secular form.
Israel is not a secular democracy. It is a religious mockery. It is a rabid bat flying to the ends of the Earth, to end the Earth. No one will be free nor safe until the disease is quarantined and dies out.
Source: http://www.ziopedia.org/articles/israel/how_can_israel_claim_to_be_a_%27dem…
--------------------
The problem with intellectually insecure whites
By Kevin MacDonald
January 19, 2009
America will soon have a white minority. This is a much desired state of affairs for the hostile elites who hold political power and shape public opinion. But it certainly creates some management issues � at least in the long run. After all, it�s difficult to come up with an historical example of a nation with a solid ethnic majority (90%
white in 1950) that has voluntarily decided to cede political and cultural power. Such transformations are typically accomplished by military invasions, great battles, and untold suffering.
And it�s not as if everyone is doing it. Only Western nations view their own demographic and cultural eclipse as a moral imperative. Indeed, as I have noted previously, it is striking that racial nationalism has triumphed in Israel at the same time that the Jewish intellectual and political movements and the organized Jewish
community have been the most active and effective force for a non-white America. Indeed, a poll in 2008 found that Avigdor Lieberman was the second most popular politician in Israel. Lieberman has advocated expulsion of Arabs from Israel and has declared himself a follower of Vladimir Jabotinsky, the leading pioneer of racial
Zionism. The most popular politician in the poll was Benjamin Netanyahu � another admirer of Jabotinsky. Prime Minister Ehud Olmert and Foreign Minister Tzipi Livni are also Jabotinskyists.
The racial Zionists are now carrying out yet another orgy of mass murder after a starvation-inducing blockade and the usual triggering assault designed to provoke Palestinian retaliation � which then becomes the cover for claims that Israel is merely defending itself against terrorism. This monstrosity was approved by
overwhelming majorities of both Houses of Congress. The craven Bush administration did its part by abstaining from a UN resolution designed by the US Secretary of State as a result of a personal appeal by the Israeli Prime Minister. This is yet another accomplishment of the Israel Lobby, but one they would rather not have
discussed in public. People might get the impression that the Lobby really does dictate US foreign policy in the Mideast. Obviously, such thoughts are only entertained by anti-Semites.
But I digress.
In managing the eclipse of white America, one strategy of the mainstream media is to simply ignore the issue. Christopher Donovan (�For the media, the less whites think about their coming minority status, the better�) has noted that the media, and in particular, the New York Times, are quite uninterested in doing stories that
discuss what white people think about this state of affairs.
It�s not surprising that the New York Times � the Jewish-owned flagship of anti-white, pro-multicultural media � ignores the issue. The issue is also missing from so-called conservative media even though one would think that conservatives would find the eclipse of white America to be an important issue. Certainly, their audiences
would find it interesting.
Now we have an article �The End of White America� written by Hua Hsu, an Assistant Professor of English at Vassar College. The article is a rather depressing display of what passes for intellectual discourse on the most important question confronting white people in America.
Hsu begins by quoting a passage in F. Scott Fitzgerald�s The Great Gatsby in which a character, Tom Buchanan, states: �Have you read The Rise of the Colored Empires by this man Goddard?� � Well, it�s a fine book, and everybody ought to read it. The idea is if we don�t look out the white race will be�will be utterly submerged.
It�s all scientific stuff; it�s been proved.�
Buchanan�s comment is a thinly veiled reference to Lothrop Stoddard�s The Rising Tide of Color which Hsu describes as �rationalized hatred� presented in a scholarly, gentlemanly, and scientific tone. (This wording that will certainly help him when he comes up for tenure.) As Hsu notes, Stoddard had a doctorate from Harvard
and was a member of many academic associations. His book was published by a major publisher. It was therefore �precisely the kind of book that a 1920s man of Buchanan�s profile � wealthy, Ivy League�educated, at once pretentious and intellectually insecure � might have been expected to bring up in casual conversation.�
Let�s ponder that a bit. The simple reality is that in the year 2009 an Ivy League-educated person, "at once pretentious and intellectually insecure," would just as glibly assert the same sort of nonsense as Hsu. To wit:
The coming white minority does not mean that the racial hierarchy of American culture will suddenly become inverted, as in 1995�s White Man�s Burden, an awful thought experiment of a film, starring John Travolta, that envisions an upside-down world in which whites are subjugated to their high-class black oppressors. There will
be dislocations and resentments along the way, but the demographic shifts of the next 40 years are likely to reduce the power of racial hierarchies over everyone�s lives, producing a culture that�s more likely than any before to treat its inhabitants as individuals, rather than members of a caste or identity group.
The fact is that no one can say for certain what multicultural America without a white majority will be like. There is no scientific or historical basis for claims like �the demographic shifts of the next 40 years are likely to reduce the power of racial hierarchies over everyone�s lives, producing a culture that�s more likely than any before
to treat its inhabitants as individuals, rather than members of a caste or identity group.�
Indeed, there is no evidence at all that we are proceeding to a color blind future. The election results continue to show that white people are coalescing in the Republican Party, while the Democrats are increasingly the party of a non-white soon-to-be majority.
Is it so hard to believe that when this coalition achieves a majority that it will further compromise the interests of whites far beyond contemporary concerns such as immigration policy and affirmative action? Hsu anticipates a colorblind world, but affirmative action means that blacks and other minorities are certainly not treated as
individuals. And it means that whites � especially white males � are losing out on opportunities they would have had without these policies and without the massive non-white immigration of the last few decades.
Given the intractability of changing intelligence and other traits required for success in the contemporary economy, it is unlikely that 40 more years of affirmative action will attain the outcomes desired by the minority lobbies. Indeed, in Obama's America, blacks are rioting in Oakland over perceived racial injustices, and from 2002
�2007, black juvenile homicide victims increased 31%, while black juvenile homicide perpetrators increased 43%. Hence, the reasonable outlook is for a continuing need for affirmative action and for racial activism in these groups, even after whites become a minority.
Whites will also lose out because of large-scale importation of relatively talented immigrants from East Asia. Indeed, as I noted over a decade ago, "The United States is well on the road to being dominated by an Asian technocratic elite and a Jewish business, professional, and media elite."
Hsu shows that there already is considerable anxiety among whites about the future. An advertizing executive says, �I think white people feel like they�re under siege right now � like it�s not okay to be white right now, especially if you�re a white male. ... People are stressed out about it. �We used to be in control! We�re losing
control�� Another says, "There�s a lot of fear and a lot of resentment."
It's hard to see why these feelings won't increase in the future.
A huge problem for white people is lack of intellectual and cultural confidence. Hsu quotes Christian (Stuff White People Like) Lander saying, "I get it: as a straight white male, I�m the worst thing on Earth." A professor comments that for his students "to be white is to be culturally broke. The classic thing white students say when
you ask them to talk about who they are is, �I don�t have a culture.� They might be privileged, they might be loaded socioeconomically, but they feel bankrupt when it comes to culture � They feel disadvantaged, and they feel marginalized."
This lack of cultural confidence is no accident. For nearly 100 years whites have been subjected to a culture of critique emanating from the most prestigious academic and media institutions. And, as Hsu points out, the most vibrant and influential aspect of American popular culture is hip-hop�a product of the African American
urban culture.
The only significant group of white people with any cultural confidence centers itself around country music, NASCAR, and the small town values of traditional white America. For this group of whites � and only this group � there is "a racial pride that dares not speak its name, and that defines itself through cultural cues instead�a
suspicion of intellectual elites and city dwellers, a preference for folksiness and plainness of speech (whether real or feigned), and the association of a working-class white minority with 'the real America.'�
This is what I term implicit whiteness � implicit because explicit assertions of white identity have been banned by the anti-white elites that dominate our politics and culture. It is a culture that, as Hsu notes, "cannot speak its name."
But that implies that the submerged white identity of the white working class and the lack of cultural confidence exhibited by the rest of white America are imposed from outside. Although there may well be characteristics of whites that facilitate this process, this suppression of white identity and interests is certainly not the natural
outcome of modernization or any other force internal to whites as a people. In my opinion, it is the result of the successful erection of a culture of critique in the West dominated by Jewish intellectual and political movements.
The result is that educated, intellectually insecure white people these days are far more likely to believe in the utopian future described by Hsu than in hard and cautious thinking about what the future might have in store for them.
It's worth dwelling a bit on the intellectual insecurity of the whites who mindlessly utter the mantras of multiculturalism that they have soaked up from the school system and from the media. Most people do not have much confidence in their intellectual ability and look to elite opinion to shape their beliefs. As I noted elsewhere,
A critical component of the success of the culture of critique is that it achieved control of the most prestigious and influential institutions of the West, and it became a consensus among the elites, Jewish and non-Jewish alike. Once this happened, it is not surprising that this culture became widely accepted among people of very
different levels of education and among people of different social classes.
Most people are quite insecure about their intellectual ability. But they know that the professors at Harvard, and the editorial page of the New York Times and the Washington Post, and even conservative commentators like Rush Limbaugh and Sean Hannity are all on page when it comes to racial and ethnic issues. This is a
formidable array, to the point that you almost have to be a crank to dissent from this consensus.
I think one of the greatest triumphs of the left has been to get people to believe that people who assert white identity and interests or who make unflattering portrayals of organized Jewish movements are morally degenerate, stupid, and perhaps psychiatrically disturbed. Obviously, all of these adjectives designate low status.
The reality is that the multicultural emperor has no clothes and, because of its support for racial Zionism and the racialism of ethnic minorities in America, it is massively hypocritical to boot. The New York Times, the academic left, and the faux conservatives that dominate elite discourse on race and ethnicity are intellectually
bankrupt and can only remain in power by ruthlessly suppressing or ignoring the scientific findings.
This is particularly a problem for college-educated whites. Like Fitzgerald's Tom Buchanan, such people have a strong need to feel that their ideas are respectable and part of the mainstream. But the respectable mainstream gives them absolutely nothing with which to validate themselves except perhaps the idea that the world
will be a better place when people like them no longer have power. Hsu quotes the pathetic Christian Lander: "�Like, I�m aware of all the horrible crimes that my demographic has done in the world. ... And there�s a bunch of white people who are desperate � desperate � to say, �You know what? My skin�s white, but I�m not one
of the white people who�s destroying the world.��
As a zombie leftist during the 1960s and 1970s, I know what that feeling of desperation is like � what it's like to be a self-hating white. We must get to the point where college-educated whites proudly and confidently say they are white and that they do not want to become a minority in America.
This reminds me of the recent docudrama Milk, which depicts the life of gay activist Harvey Milk. Milk is sure be nominated for an Oscar as Best Picture because it lovingly illustrates a triumph of the cultural left. But is has an important message that should resonate with the millions of whites who have been deprived of their
confidence and their culture: Be explicit. Just as Harvey Milk advocated being openly gay even in the face of dire consequences, whites need to tell their family and their friends that they have an identity as a white person and believe that whites have legitimate interests as white people. They must accept the consequences
when they are harassed, fired from their jobs, or put in prison for such beliefs. They must run for political office as openly pro-white.
Milk shows that homosexuals were fired from their jobs and arrested for congregating in public. Now it's the Southern Poverty Law Center and the rest of the leftist intellectual and political establishment that harasses and attempts to get people fired. But it's the same situation with the roles reversed. No revolution was ever
accomplished without some martyrs. The revolution that restores the legitimacy of white identity and the legitimacy of white interests will be no exception.
But it is a revolution that is absolutely necessary. The white majority is foolish indeed to entrust its future to a utopian hope that racial and ethnic identifications will disappear and that they won�t continue to influence public policy in ways that compromise the interests of whites.
It does not take an overactive imagination to see that coalitions of minority groups could compromise the interests of formerly dominant whites. We already see numerous examples in which coalitions of minority groups attempt to influence public policy, including immigration policy, against the interests of the whites. Placing
ourselves in a position of vulnerability would be extremely risky, given the deep sense of historical grievance fostered by many ethnic activists and organized ethnic lobbies.
This is especially the case with Jews. Jewish organisations have been unanimous in condemning Western societies, Western traditions, and Christianity, for past crimes against Jews. Similar sentiments are typical of a great many African Americans and Latinos, and especially among the ethnic activists from these groups. The
�God damn America� sermon by President Obama's pastor comes to mind as a recent notorious example.
The precedent of the early decades of the Soviet Union should give pause to anyone who believes that surrendering ethnic hegemony does not carry risks. The Bolshevik revolution had a pronounced ethnic angle: To a very great extent, Jews and other non-Russians ruled over the Russian people, with disastrous
consequences for the Russians and other ethnic groups that were not able to become part of the power structure. Jews formed a hostile elite within this power structure � as they will in the future white-minority America; Jews were �Stalin�s willing executioners.�
Two passages from my review of Yuri Slezkine's The Jewish Century seem particularly appropriate here. The first passage reminds me of the many American Jews who adopt a veneer of support for leftist versions of social justice and racial tolerance while nevertheless managing to support racial Zionism and the mass murder,
torture, and incarceration of the Palestinian people in one of the largest prison systems the world has ever seen. Such people may be very different when they become a hostile elite in a white-minority America.
Many of the commentators on Jewish Bolsheviks noted the �transformation� of Jews [after the Bolshevik Revolution]. In the words of [a] Jewish commentator, G. A. Landau, �cruelty, sadism, and violence had seemed alien to a nation so far removed from physical activity.� And another Jewish commentator, Ia. A. Bromberg, noted
that:
the formerly oppressed lover of liberty had turned into a tyrant of �unheard-of-despotic arbitrariness��. The convinced and unconditional opponent of the death penalty not just for political crimes but for the most heinous offenses, who could not, as it were, watch a chicken being killed, has been transformed outwardly into a
leather-clad person with a revolver and, in fact, lost all human likeness. ...
After the Revolution, ... there was active suppression of any remnants of the older order and their descendants. ... The mass murder of peasants and nationalists was combined with the systematic exclusion of the previously existing non-Jewish middle class. The wife of a Leningrad University professor noted, �in all the
institutions, only workers and Israelites are admitted; the life of the intelligentsia is very hard� (p. 243). Even at the end of the 1930s, prior to the Russification that accompanied World War II, �the Russian Federation�was still doing penance for its imperial past while also serving as an example of an ethnicity-free society� (p. 276).
While all other nationalities, including Jews, were allowed and encouraged to keep their ethnic identities, the revolution remained an anti-majoritarian movement.
The difference from the Soviet Union may well be that in white-minority America it will not be workers and Israelites who are favored, but non-whites and Israelites. Whites may dream that they are entering the post-racial utopia imagined by their erstwhile intellectual superiors. But it is quite possible that they are entering into a
racial dystopia of unimaginable cruelty in which whites will be systematically excluded in favor of the new elites recruited from the soon-to-be majority. It's happened before.
Kevin MacDonald is a professor of psychology at California State University�Long Beach.
Permanent URL with hyperlinks:
http://www.theoccidentalobserver.net/articles/MacDonald-Hsu.html
-----------
Should Christians Support Israeli Terrorism in Gaza?
A timely discussion between Rev. Ted Pike and Dr. David Duke, one especially important for the Christians in our audience
http://www.davidduke.com/mp3/dukeradio090122DukeandPikeonGaza.mp3
In this vital discussion, Rev. Pike and Dr. Duke explore the Pro-Israel attitude of some Christian evangelical organizations, and why their position not only goes directly against Christian morality and decency, but actually is directly opposite of that expressed by Christian Scriptures. Today, Many Christians are instructed that Jews
and today�s Israel has a special covenant� with God. In fact, the New Testament in the clearest of language states that the Jews �continued not in my covenant, and I considered them not, saith the Lord.� Here�s the quote that Christians aren�t supposed to notice.:
8:10 Not according to the covenant that I made with their fathers, in the day when I took them by the hand out of the land of Egypt; because they continued not in my covenant, and I regarded them not, saith the Lord. (Hebrews 8:10)
They also don�t seem to notice that a 2000 year old Judaic war against Christianity that has been waged since time of Jesus Christ and still goes on today with the most powerful Jewish organizations attempting to destroy European and American traditions, that has even become a war on our Christmas traditions.
Dr. Duke and Ted Pike also speak about how over a hundred thousand Christian Palestinians have suffered with their families from anti-Christian Israel! Christian support of Israel has resulted in the very birthplace of Jesus Christ, go from 90 percent Palestinian Christians to 35 percent today because of Israeli terror and
occupation. They ask, �How could any Christian in good conscience support the anti-Christian state of Israel, bombing the homes, killing and maiming, torturing and oppressing fellow Christian men, women and children?�
This is a vital show for every Christian reader and listener of DavidDuke.com. Next time, you hear someone say, �God tells us that we must support Israel� you will have the clear Christian answer that just the opposite is true!
For documentation on this be sure to read some of the well-footnoted, sample chapters of Jewish Supremacism and My Awakening.
Source :
http://www.davidduke.com/general/should-christians-support-israeli-terroris…
-------------------------------------
You or someone using your email adress is currently subscribed to the Lawrence Auster
Newletter. If you wish to unsubscribe from our mailing list, please let us know by calling to 1 212 865 1284
Thanks,
Lawrence Auster,
238 W 101 St Apt. 3B
New York, NY 10025
Contact: lawrence.auster(a)att.net
-------------------------------------
1
0
Author: sburson
Date: Sat Jan 6 18:32:32 2007
New Revision: 2
Added:
misc-extensions.asd
Log:
Initial commit.
Added: misc-extensions.asd
==============================================================================
--- (empty file)
+++ misc-extensions.asd Sat Jan 6 18:32:32 2007
@@ -0,0 +1,8 @@
+;;; -*- Lisp -*-
+
+(defsystem misc-extensions
+ :serial t
+ :components ((:module "src"
+ :components ((:file "defs")
+ (:file "new-let")
+ (:file "gmap")))))
1
0
Author: sburson
Date: Sat Jan 6 18:32:18 2007
New Revision: 1
Added:
src/
src/defs.lisp
src/gmap.lisp
src/new-let.lisp
Log:
Initial commit.
Added: src/defs.lisp
==============================================================================
--- (empty file)
+++ src/defs.lisp Sat Jan 6 18:32:18 2007
@@ -0,0 +1,17 @@
+;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Package: CL-User -*-
+
+;;; This file is in the public domain. It is provided with ABSOLUTELY
+;;; NO WARRANTY.
+
+(in-package :cl-user)
+
+(defpackage :new-let
+ (:use :cl)
+ (:shadow cl:let cl:cond)
+ (:export #:let #:cond #:nlet #:bcond))
+
+(defpackage :gmap
+ (:use :cl)
+ (:export #:gmap)
+ (:import-from :new-let #:nlet #:bcond))
+
Added: src/gmap.lisp
==============================================================================
--- (empty file)
+++ src/gmap.lisp Sat Jan 6 18:32:18 2007
@@ -0,0 +1,617 @@
+; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Package: (GMAP Common-Lisp) -*-
+(in-package gmap)
+
+;
+; GMAP, version 3.2, by Scott L. Burson
+;
+; This file is in the public domain.
+;
+; The GMAP macro provides a new kind of iteration facility in LISP.
+; Basically, it is intended for when you would like to use MAPCAR, but
+; can't because the things you want to map over aren't in lists, or you
+; need to collect the results of the mapping into something other than a
+; list. That is, GMAP is probably the right thing to use when you are
+; using iteration to perform the same computation on each element of
+; some collection, as opposed to changing your state in some complicated
+; way on every iteration of a loop.
+; In fact, it's conceptually reasonable to imagine all the iterations of a
+; GMAP as happening in parallel, just as you might with MAPCAR. The
+; difference is that with GMAP you explicitly say, via keywords, what kinds
+; of collections the elements come in and what kind of collection to make
+; from the result. For example, the following two expressions are equivalent:
+; (mapcar #'foo this-list that-list) and
+; (gmap :list #'foo (:list this-list) (:list that-list))
+; The first :list keyword indicates that GMAP is to build a list; the other
+; two tell it that this-list and that-list are in fact lists of elements over
+; which foo is to be mapped. Other keywords exist besides :list; for
+; example, :string, if used as an argument keyword, causes its argument
+; to be viewed as a string; the values it "generates" for the function being
+; mapped are the successive characters of the string.
+; Perhaps the best feature of GMAP is its facility for defining one's own
+; keywords. Thus you can adapt it to other kinds of data structures over
+; which you would like to iterate.
+;
+; The overall syntax of GMAP is:
+; (gmap <result-spec> <fn>
+; <arg-spec-0>
+; <arg-spec-1>
+; ... )
+; where <fn> is the function being mapped, just like the first argument
+; to MAPCAR. The <result-spec> and the <arg-spec-i> are lists, whose first
+; element is a keyword indicating the type of result constructor or argument
+; generator, and the interpretation of whose subsequent elements depends on
+; that type. For example, in:
+; (gmap :list #'+
+; (:list '(14 32 51))
+; (:index 3))
+; #'+ is the function to be mapped;
+; the result-type of :list specifies that a list is to be constructed containing
+; the results;
+; the first arg-spec specifies that the first argument to the function
+; being mapped will be successive elements of the list '(14 32 51);
+; and the second arg-spec says that the second argument will be successive
+; integers starting with 3.
+; The result, of course, is (17 36 56).
+;
+; **** Argument generators ****
+; Each generator is given one variable in which to maintain its state. We have
+; to tell GMAP explicitly how to get from the current value of the state variable
+; to a)the value to be generated and b)the next value of the state variable.
+;
+; The keyword, the first element, of each argument spec tells what kind of
+; generator to use. NIL as a keyword specifies that one is defining a generator
+; for this instance of GMAP only instead of using one of the predefined ones.
+; A NIL-type arg-spec has the following syntax:
+; (nil <init> &optional <exitp> <argfn> <nextfn> <let-specs>)
+; where <init> is the initial value of the generator's state variable;
+; <exitp>, if non-nil, is a function of one argument; when it becomes true of
+; [i.e., returns a non-nil value when applied to] the state variable, the
+; iteration terminates. If it is absent or nil, this generator has no exit-test.
+; If more than one arg-spec supplies an exitp, then the
+; first one to finish terminates the entire iteration [just like mapcar, which
+; stops when any list runs out].
+; <argfn>, if non-nil, is a function of one argument which is applied to the
+; current value of the state variable to get the value the generator actually
+; returns on this iteration.
+; <nextfn>, if non-nil, is a function of one argument which takes the current
+; value of the state variable and returns the next.
+; <let-specs> facilitates arbitrary hair and is explained below.
+; For example, an arg-spec of (:list foo) is equivalent to
+; (nil foo #'null #'car #'cdr)
+; where foo is the initial value of the list; #'null is the predicate that says
+; when the list has run out; #'car, the argfn, is what is done to the list to
+; get the current element; and #'cdr, the nextfn, is what is done to the list
+; to get the next list.
+;
+; An argument generator described this way is conceptually equivalent to
+; (let `(state-var ,@<let-specs>)
+; #'(lambda ()
+; (if (<exitp> state-var)
+; (*throw 'exit-iteration nil)
+; (prog1 (<argfn> state-var)
+; (setq state-var (<nextfn> state-var))))))
+;
+; Note that if only (nil <init>) is specified, the argument is a constant <init>;
+; no more circular-list'ing!
+;
+; Other predefined argument types include:
+; (:constant <value>)
+; A more readable version of `(nil <value>)'.
+; (:list <list>)
+; As shown in examples above: supplies successive elements of <list>.
+; (:index <start> &optional <stop> <incr>)
+; Provides numbers beginning at <start> and going to (but not including) <stop>
+; incrementing by <incr> each time. If <stop> is missing or nil, this generates
+; numbers indefinitely. <incr> may be positive or negative and defaults to 1.
+; (:index-inc <start> <stop> &optional <incr>)
+; "Index, INClusive": like :index, but the numbers generated include <stop>.
+; (:vector <vector>)
+; Generates successive elements of <vector>.
+; (:simple-vector <vector>)
+; Generates successive elements of <vector> (which must be simple).
+; (:string <string>)
+; Generates successive characters of <string>.
+; (:simple-string <string>)
+; Generates successive characters of <string> (which must be simple).
+; (:exp <initial-value> <base>)
+; Generates an exponential sequence whose first value is <initial-value>, and
+; whose value is multiplied by <base> on each iteration.
+;
+; **** Result Constructors ****
+; Like arg-specs, result-specs begin with a keyword saying what kind of
+; constructor to use, i.e., how to put together the results of the function
+; being mapped. And again, a keyword of NIL means that no predefined
+; constructor is being used. A NIL-type result-spec looks like:
+; (nil <init> <resfn> &optional <cleanup> <filterp> <let-specs>)
+; where
+; <init> is the initial value of the constructor's state variable;
+; <resfn> is a function of two arguments, the current value of the state variable
+; and the current value returned by the function being mapped; it gives the next
+; value of the state variable.
+; <cleanup>, if present and non-nil, is a function of one argument that
+; translates the final value of the state variable into the value that the GMAP
+; actually returns.
+; <filterp>, if present and non-nil, is a predicate of one argument; when it is false
+; of the current value of the function being mapped, <resfn> is not called on that
+; iteration, and the value of the state variable is unchanged.
+; <let-specs>, as before, is hairy; I'll get back to it below.
+; For example, a res-spec of (:list) is equivalent to
+; (nil nil #'(lambda (a b) (cons b a)) #'nreverse)
+; -- the state variable starts at nil, gets successive values consed onto it, and
+; gets nreversed before being returned.
+;
+; A result-spec that supplies no arguments may be written without the parens; so
+; (:list) and :list are equivalent.
+;
+; Other predefined result types include:
+; :list
+; Generates a list, like mapcar, of the values.
+; :and
+; Returns the first NIL, or the last value if none are NIL.
+; :or
+; Returns the first non-NIL, or NIL if all values are NIL.
+; :sum
+; Returns the sum of the values. E.g., to get sum of products, use
+; (gmap :sum #'* ...)
+; (:array <initial-array>)
+; Generates an array of the values. You supply the initial array; the values
+; are stored starting with element 0. If the array has a fill pointer, it is
+; set upon exit to the number of elements stored. The array itself is returned.
+; (:string &optional <length-guess>)
+; Generates a string from the values. <length-guess> is the initially allocated
+; string size; it defaults to 20. #'array-push-extend is used to append each
+; character.
+; (:values &rest <result-specs>)
+; The function being mapped is expected to return as many values as there are
+; result-specs; each value is accumulated separately according to its respective
+; result-spec, and finally, all the result values are returned.
+;
+; **** User-defined argument and result types ****
+; A useful feature of GMAP is the provision for the user to define his/her own
+; argument generators and result constructors. For example, if in some program you
+; commonly iterate over words in a sentence, or lines in an editor buffer, or users
+; currently logged on, then define an argument type SENTENCE, or LINES, or USERS.
+; And similarly with result-types. The way this is done [which I'm not yet sure is
+; entirely satisfactory] is with the two special forms DEF-GMAP-ARG-TYPE and
+; DEF-GMAP-RES-TYPE. These have syntax like DEFUN:
+; (def-gmap-foo-type <name> (<args>)
+; <body>)
+; When <name> is seen as the keyword of an arg- or result-spec, and has
+; been defined with the appropriate special form, then the function
+; #'(lambda (<args>) <body>) is applied to the cdr of the spec; that is,
+; the keyword itself has been stripped off. Whatever this returns is interpreted
+; as a nil-type spec, except, again, without the keyword "nil". For example, the
+; arg-type :list is actually defined by
+; (def-gmap-arg-type :list (initial-list)
+; `(,initial-list ; init
+; #'null #'car #'cdr)) ; exitp, argfn, and resfn
+;
+; Lists of what arg- and result-types are defined can be found in the variables
+; *GMAP-ARG-TYPE-LIST* and *GMAP-RES-TYPE-LIST*.
+;
+; Now for the promised explanation about let-specs. Sometimes [indeed, fairly
+; often] a user-defined type will want to compute values and bind variables
+; other than those automatically provided by the iteration. For example, the
+; index type goes to some trouble to evaluate its parameters only once. It does
+; this by providing a list of specs, i.e., (<var> <value>) pairs, which go into
+; a LET that surrounds the entire iteration. Except, that is, for the following
+; hack: if you want several dependent initializations, e.g., you want foo to be
+; something hairy and bar to be the cdr of foo, you can indicate the dependence
+; by the nesting in list structure of the specs:
+; ((foo (something-hairy))
+; ((bar (cdr foo))))
+; This will cause a gmap that uses this type to expand into
+; (let ((foo (something-hairy)))
+; (let ((bar (cdr foo)))
+; ... [iteration] ...))
+; For details, see the NLET macro at the end of this file. For examples,
+; see some of the types defined herein.
+
+; Remaining tidbits:
+; Many arg- and result-specs take optional parameters, which are defined to do
+; something only if both present and non-nil. By "non-nil" here I mean non-nil
+; *at expansion time*.
+; The function being mapped can itself be nil, subject of course to the above
+; considerations; in which case the identity function of the first argument is
+; used, and other arguments are ignored.
+
+; Bugs:
+;
+; Purists will object to the use of symbols in the keyword package rather than
+; the `lisp' package for the arg- and result-types. It would make sense for
+; these symbols to come from the package providing the types they refer to;
+; among other advantages, this would prevent name collisions (which is, after
+; all, the whole point of the package system). Against this very reasonable
+; argument is my desire to have it immediately apparent to someone seeing a
+; `gmap' form, perhaps for the first time, that it is a macro with somewhat
+; unusual syntax; the use of ordinary Lisp symbols (`list', `vector', etc.)
+; would tend to disguise this fact. Anyway, there's nothing requiring the arg-
+; and result-type names to be in the keyword package; anyone who strongly
+; dislikes this is welcome to define names in some other package.
+
+; The top-level macro.
+(defmacro gmap (res-spec fn &rest arg-spec-list)
+ (gmap>expand fn
+ (gmap>res-spec-lookup res-spec)
+ (mapcar #'gmap>arg-spec-lookup arg-spec-list)))
+
+; This does the real work.
+(defun gmap>expand (fn res-specs arg-spec-list)
+ (let ((param-list
+ (mapcar #'gmap>param arg-spec-list))
+ (result-list (gmap>res>init-clauses res-specs))
+ (let-specs (gmap>let-specs arg-spec-list res-specs)))
+ (let ((one-value-p (null (cdr result-list)))
+ (fnval-vars (mapcar #'(lambda (ignore)
+ (declare (ignore ignore))
+ (gensym))
+ result-list)))
+ `(nlet ,let-specs
+ (do (,@param-list
+ ,@result-list)
+ ((or ,@(apply #'append (mapcar #'gmap>param>exit-test ; exit test
+ param-list arg-spec-list)))
+ ,(gmap>res>cleanup res-specs result-list one-value-p))
+ ,(if one-value-p
+ (if (car fnval-vars)
+ `(let ((,(car fnval-vars)
+ ,(apply #'gmap>funcall fn
+ (mapcar #'gmap>param>arg param-list arg-spec-list))))
+ (setq ,(caar result-list)
+ ,(gmap>res>next (car res-specs) (caar result-list)
+ (car fnval-vars))))
+ #| Null result spec -- just call the function for effect. |#
+ (apply #'gmap>funcall fn
+ (mapcar #'gmap>param>arg param-list arg-spec-list)))
+ `(multiple-value-bind ,fnval-vars
+ ,(apply #'gmap>funcall fn
+ (mapcar #'gmap>param>arg param-list arg-spec-list))
+ . ,(mapcar #'(lambda (fnval result-pair res-spec)
+ `(setq ,(car result-pair)
+ ,(gmap>res>next res-spec (car result-pair) fnval)))
+ fnval-vars result-list res-specs))))))))
+
+
+; extract the let-specs.
+(defun gmap>let-specs (arg-specs res-specs)
+ (nconc (mapcan #'fifth arg-specs) (mapcan #'fifth res-specs)))
+
+; generate the do-variable spec for each argument.
+(defun gmap>param (arg-spec)
+ (let ((param-name (gensym))
+ (init (first arg-spec))
+ (nextfn (fourth arg-spec)))
+ `(,param-name
+ ,init
+ ,@(if nextfn
+ `(,(gmap>funcall nextfn param-name))
+ nil))))
+
+; get the argument to the function being mapped from the do-variable.
+(defun gmap>param>arg (param arg-spec)
+ (let ((param-name (first param))
+ (argfn (third arg-spec)))
+ (gmap>funcall argfn param-name)))
+
+; get the exit test for the variable.
+(defun gmap>param>exit-test (param arg-spec)
+ (let ((param-name (first param))
+ (exitp (second arg-spec)))
+ (if exitp
+ `(,(gmap>funcall exitp param-name))
+ nil)))
+
+; get the initial value of the result.
+(defun gmap>res>init-clauses (res-specs)
+ (mapcan #'(lambda (res-spec) (and res-spec (cons (list (gensym) (first res-spec)) nil)))
+ res-specs))
+
+; compute the next value of the result from the current one and the
+; current value of the function.
+(defun gmap>res>next (res-spec result fnval)
+ (let ((resfn (second res-spec))
+ (filterp (fourth res-spec)))
+ (if filterp
+ `(if ,(gmap>funcall filterp fnval)
+ ,(gmap>funcall resfn result fnval)
+ ,result)
+ (gmap>funcall resfn result fnval))))
+
+; call the cleanup function on exit.
+(defun gmap>res>cleanup (res-specs result-list one-value-p)
+ (if one-value-p
+ (gmap>funcall (third (car res-specs)) (caar result-list))
+ `(values . ,(mapcar #'(lambda (res-spec result-pair)
+ (gmap>funcall (third res-spec) (car result-pair)))
+ res-specs result-list))))
+
+; For some reason, the compiler doesn't convert, e.g., (funcall #'car foo)
+; to (car foo); thus we lose some efficiency for functions that would normally
+; open-code, like car. Hence this function to perform the optimization for it.
+(defun gmap>funcall (function &rest args)
+ (let ((args (copy-list args)))
+ (cond ((or (null function) (eq function ':id))
+ (car args))
+ ((and (listp function)
+ (eq (car function) 'function))
+ `(,(cadr function) . ,args))
+ (t `(funcall ,function . ,args)))))
+
+
+
+(eval-when (:execute :compile-toplevel :load-toplevel)
+ (defvar *gmap-arg-type-list* nil
+ "A list of all GMAP arg types that have been defined.")
+ (defvar *gmap-res-type-list* nil
+ "A list of all GMAP result types that have been defined."))
+
+; define an arg-type.
+(defmacro def-gmap-arg-type (name args &body body)
+ (let ((fn-name (gensym "GMAP-ARG-SPEC-EXPANDER-")))
+ `(progn
+ 'compile
+ (defun ,fn-name ,args . ,body)
+ (eval-when (:execute :compile-toplevel :load-toplevel)
+ (setf (get ',name ':gmap-arg-spec-expander) ',fn-name)
+ (pushnew ',name *gmap-arg-type-list*)))))
+
+; define a result-type.
+(defmacro def-gmap-res-type (name args &body body)
+ (let ((fn-name (gensym "GMAP-RES-SPEC-EXPANDER-")))
+ `(progn
+ 'compile
+ (defun ,fn-name ,args . ,body)
+ (eval-when (:execute :compile-toplevel :load-toplevel)
+ (setf (get ',name ':gmap-res-spec-expander) ',fn-name)
+ (pushnew ',name *gmap-res-type-list*)))))
+
+; look up an arg type.
+(defun gmap>arg-spec-lookup (raw-arg-spec)
+ (let ((type (car raw-arg-spec)))
+ (if (null type)
+ (cdr raw-arg-spec)
+ (let ((generator (get type ':gmap-arg-spec-expander)))
+ (if generator
+ (apply generator (cdr raw-arg-spec))
+ (error "Argument spec, ~S, to gmap is of unknown type
+ (Do you have the package right?)"
+ raw-arg-spec))))))
+
+; look up a result type.
+(defun gmap>res-spec-lookup (raw-res-spec)
+ (if (and (listp raw-res-spec)
+ (eq (car raw-res-spec) ':values))
+ (mapcar #'gmap>res-spec-lookup-1 (cdr raw-res-spec))
+ (cons (gmap>res-spec-lookup-1 raw-res-spec) nil)))
+(defun gmap>res-spec-lookup-1 (raw-res-spec)
+ (let ((type (if (listp raw-res-spec) (car raw-res-spec)
+ raw-res-spec)))
+ (if (null type)
+ (cdr raw-res-spec)
+ (let ((generator (get type ':gmap-res-spec-expander)))
+ (if generator
+ (apply generator (and (listp raw-res-spec) (cdr raw-res-spec)))
+ (error "Result spec, ~S, to gmap is of unknown type
+ (Do you have the package right?)"
+ raw-res-spec))))))
+
+
+
+; ******** Predefined argument types ********
+; See above for documentation.
+
+(def-gmap-arg-type :constant (value)
+ `(,value))
+
+(def-gmap-arg-type :list (initial-list)
+ `(,initial-list
+ #'null #'car #'cdr))
+
+(def-gmap-arg-type :index (start &optional stop incr)
+ (let ((incr-temp (gensym))
+ (stop-temp (gensym))
+ (bounds-fn-temp (gensym)))
+ `(,start ; init
+ ,(if stop ; exitp
+ (if incr
+ `#'(lambda (val)
+ (funcall ,bounds-fn-temp val ,stop-temp))
+ `#'(lambda (val) (declare (type fixnum val))
+ (>= val ,stop-temp)))
+ 'nil)
+ nil ; no argfn
+ ,(if incr ; nextfn
+ `#'(lambda (val) (declare (type fixnum val))
+ (+ val ,incr-temp))
+ '#'1+)
+ (,@(if incr ; and let-specs
+ `((,incr-temp ,incr)
+ ((,bounds-fn-temp (if (minusp ,incr-temp) #'<= #'>=)))))
+ ,@(if stop
+ `((,stop-temp ,stop)))))))
+
+(def-gmap-arg-type :index-inc (start &optional stop incr)
+ (let ((incr-temp (gensym))
+ (stop-temp (gensym))
+ (bounds-fn-temp (gensym)))
+ `(,start ; init
+ ,(if stop ; generate (possibly hairy) exitp
+ (if incr
+ `#'(lambda (val)
+ (funcall ,bounds-fn-temp val ,stop-temp))
+ `#'(lambda (val) (declare (type fixnum val))
+ (> val ,stop-temp)))
+ 'nil)
+ nil ; no argfn
+ ,(if incr ; nextfn
+ `#'(lambda (val) (declare (type fixnum val))
+ (+ val ,incr-temp))
+ '#'1+)
+ (,@(if incr ; and let-specs
+ `((,incr-temp ,incr)
+ ((,bounds-fn-temp (if (minusp ,incr-temp) #'< #'>)))))
+ ,@(if stop
+ `((,stop-temp ,stop)))))))
+
+;;; Deprecated; use `:vector'.
+(def-gmap-arg-type :array (array &optional start stop incr)
+ (let ((array-temp (gensym))
+ (incr-temp (and incr (gensym)))
+ (stop-temp (gensym)))
+ `(,(or start 0)
+ #'(lambda (i) (>= i ,stop-temp))
+ #'(lambda (i) (aref ,array-temp i))
+ #'(lambda (x) (+ x ,(or incr-temp 1)))
+ ((,array-temp ,array)
+ ,@(and incr `((,incr-temp ,incr)))
+ ((,stop-temp ,(or stop `(length ,array-temp))))))))
+
+(def-gmap-arg-type :vector (array &optional start stop incr)
+ (let ((array-temp (gensym))
+ (incr-temp (and incr (gensym)))
+ (stop-temp (gensym)))
+ `(,(or start 0)
+ #'(lambda (i) (>= i ,stop-temp))
+ #'(lambda (i) (aref ,array-temp i))
+ #'(lambda (x) (+ x ,(or incr-temp 1)))
+ ((,array-temp ,array)
+ ,@(and incr `((,incr-temp ,incr)))
+ ((,stop-temp ,(or stop `(length ,array-temp))))))))
+
+(def-gmap-arg-type :simple-vector (array &optional start stop incr)
+ (let ((array-temp (gensym))
+ (incr-temp (and incr (gensym)))
+ (stop-temp (gensym)))
+ `(,(or start 0)
+ #'(lambda (i) (declare (type fixnum i)) (>= i ,stop-temp))
+ #'(lambda (i) (declare (type fixnum i)) (svref ,array-temp i))
+ #'(lambda (i) (declare (type fixnum i)) (+ i ,(or incr-temp 1)))
+ ((,array-temp ,array)
+ ,@(and incr `((,incr-temp (the fixnum ,incr))))
+ ((,stop-temp (the fixnum ,(or stop `(length ,array-temp)))))))))
+
+; This is like :array but coerces the object to a string first.
+(def-gmap-arg-type :string (string &optional start stop incr)
+ (let ((string-temp (gensym))
+ (incr-temp (and incr (gensym)))
+ (stop-temp (gensym)))
+ `(,(or start 0)
+ #'(lambda (i) (>= i ,stop-temp))
+ #'(lambda (i) (char ,string-temp i))
+ #'(lambda (x) (+ x ,(or incr-temp 1)))
+ ((,string-temp (string ,string))
+ ,@(and incr `((,incr-temp ,incr)))
+ ((,stop-temp ,(or stop `(length ,string-temp))))))))
+
+(def-gmap-arg-type :simple-string (string &optional start stop incr)
+ (let ((string-temp (gensym))
+ (incr-temp (and incr (gensym)))
+ (stop-temp (gensym)))
+ `(,(or start 0)
+ #'(lambda (i) (>= i ,stop-temp))
+ #'(lambda (i) (schar ,string-temp i))
+ #'(lambda (x) (+ x ,(or incr-temp 1)))
+ ((,string-temp (string ,string))
+ ,@(and incr `((,incr-temp ,incr)))
+ ((,stop-temp ,(or stop `(length ,string-temp))))))))
+
+
+; ******** Predefined result types ********
+
+(def-gmap-res-type :list (&optional filterp)
+ `(nil #'xcons #'nreverse ,filterp))
+
+(defun xcons (a b)
+ (cons b a))
+
+(def-gmap-res-type :nconc (&optional filterp)
+ (let ((result-var (gensym))) ; have to use our own, sigh.
+ `(nil ; init
+ #'(lambda (tail-loc new) ; nextfn
+ (if tail-loc (rplacd tail-loc new)
+ (setq ,result-var new))
+ (if new (last new) tail-loc))
+ #'(lambda (ignore)
+ (declare (ignore ignore))
+ ,result-var)
+ ,filterp
+ ((,result-var nil)))))
+
+(def-gmap-res-type :and ()
+ '(t #'(lambda (ignore new)
+ (declare (ignore ignore))
+ (if new new (return nil)))))
+
+(def-gmap-res-type :or ()
+ '(nil #'(lambda (ignore new)
+ (declare (ignore ignore))
+ (if new (return new) nil))))
+
+(def-gmap-res-type :sum ()
+ '(0 #'+))
+
+(def-gmap-res-type :count-if ()
+ '(0 #'(lambda (n new)
+ (if new (1+ n) n))))
+
+(def-gmap-res-type :max ()
+ '(nil #'max-with-nil-id))
+
+(defun max-with-nil-id (x y)
+ (if (null x) y
+ (if (null y) x
+ (max x y))))
+
+(def-gmap-res-type :min ()
+ '(nil #'min-with-nil-id))
+
+(defun min-with-nil-id (x y)
+ (if (null x) y
+ (if (null y) x
+ (min x y))))
+
+;;; Deprecated; use `:vector'.
+(def-gmap-res-type :array (initial-empty-array)
+ (let ((array-temp (gensym)))
+ `(0 ; init
+ #'(lambda (curr-index next-elt) ; nextfn
+ (setf (aref ,array-temp curr-index) next-elt)
+ (1+ curr-index))
+ #'(lambda (last-index) ; cleanup
+ (if (array-has-fill-pointer-p ,array-temp)
+ (setf (fill-pointer ,array-temp) last-index))
+ ,array-temp)
+ nil ; filterp
+ ((,array-temp ,initial-empty-array))))) ; let-specs
+
+(def-gmap-res-type :vector (initial-empty-vector)
+ (let ((vector-temp (gensym)))
+ `(0 ; init
+ #'(lambda (curr-index next-elt) ; nextfn
+ (setf (aref ,vector-temp curr-index) next-elt)
+ (1+ curr-index))
+ #'(lambda (last-index) ; cleanup
+ (if (vector-has-fill-pointer-p ,vector-temp)
+ (setf (fill-pointer ,vector-temp) last-index))
+ ,vector-temp)
+ nil ; filterp
+ ((,vector-temp ,initial-empty-vector))))) ; let-specs
+
+(def-gmap-res-type :string (&optional (length-guess 20.))
+ `((make-array ,length-guess ; init
+ :element-type :character
+ :adjustable t :fill-pointer 0)
+ #'(lambda (string char) ; nextfn
+ (vector-push-extend char string)
+ string)))
+
+(def-gmap-arg-type :exp (initial-value base)
+ (let ((base-temp (gensym)))
+ `(,initial-value
+ nil
+ nil
+ #'(lambda (x) (* x ,base-temp))
+ ((,base-temp ,base)))))
+
+
+; End of gmap.lisp
Added: src/new-let.lisp
==============================================================================
--- (empty file)
+++ src/new-let.lisp Sat Jan 6 18:32:18 2007
@@ -0,0 +1,327 @@
+(in-package :new-let)
+
+;;; This file is in the public domain.
+
+;;; This code implements a new LET macro with expanded syntax and semantics,
+;;; a generalization of LET, LET*, and MULTIPLE-VALUE-BIND. Some examples:
+;;;
+;;; (let ((a (foo))
+;;; ((b (bar a))))
+;;; ...)
+;;;
+;;; This example illustrates that clause nesting depth is used to indicate
+;;; ordering of evaluation and binding. B is bound after A, and its initial
+;;; value expression refers to A.
+;;;
+;;; (let ((a b c (zot))
+;;; ((d (quux a c))
+;;; ((e f (mumble b d))
+;;; (g (mung a))))
+;;; ((h (frobozz c))
+;;; ((i (xyzzy h))))
+;;; (*print-level* 3))
+;;; ...)
+;;;
+;;; A, B, and C are bound to the first three values of (ZOT), and in parallel,
+;;; *PRINT-LEVEL* is bound to 3; then D and H are bound; then E, F, G, and I
+;;; are bound.
+;;;
+;;; As this example illustrates, all bindings at a given nesting level are
+;;; done in parallel, with all bindings at a deeper level following.
+;;;
+;;; Since I like to use multiple values, I find this syntax for binding them
+;;; very handy, and I think many will agree. (Those familiar with Dylan
+;;; will think that I have borrowed the idea from it, but I wrote the first
+;;; version of this macro in 1980.) The value of using nesting to indicate
+;;; sequencing will perhaps be less clear. The additional flexibility
+;;; provided, compared to LET*, is admittedly rarely of importance in terms
+;;; of expressing an idea in fewer keystrokes. Personally, though, I like
+;;; being able to indicate clearly the data flow dependences among the
+;;; various variables I may be binding in one LET; and I have written LET
+;;; expressions of complexity comparable to the second example above. (I
+;;; should emphasize that the breaking up of the clauses into groups, as in
+;;; that second example, to emphasize their data dependence relationships
+;;; is strictly for clarity; in fact, the initial value expression for G,
+;;; for instance, is within the scope of H.)
+;;;
+;;; This code also implements an extension to COND. It is simply this: that
+;;; if the predicate expression of a COND clause is a LET form, the scope of
+;;; all variables bound by the LET is extended to include the consequent
+;;; expressions of the clause. (However, it does not include subsequent
+;;; clauses.) This simplifies the writing of somewhat Prolog-like code that
+;;; simultaneously tests that an object has a certain structure and binds
+;;; variables to parts of that structure in order to do something else.
+;;; (In order to be recognized as such, the predicate expression must be
+;;; written as a LET form, not a macro invocation that expands to a LET form.
+;;; I think this is a feature, but am open to being persuaded otherwise.)
+;;;
+;;; To use these macros, you must shadow the standard definitions in your
+;;; package. This can be done by including the following option clause in
+;;; your DEFPACKAGE form:
+;;;
+;;; (:shadowing-import-from "NEW-LET" "LET" "COND")
+;;;
+;;; If for some reason you don't want to shadow these, you can access this
+;;; version of LET as NLET, and this version of COND as BCOND (the "B" is
+;;; for "binding"), by using the following DEFPACKAGE option instead:
+;;;
+;;; (:import-from "NEW-LET" "NLET" "BCOND")
+;;;
+;;; Enjoy!
+;;; Scott L. Burson 2/18/2005
+
+
+(defmacro let (clauses &body body)
+ "A generalization of CL:LET that better supports nested bindings and multiple
+values. Syntax: (let (<clause>*) <body>). The <clause> syntax is more general
+than for CL:LET:
+ <clause> ::= <symbol> ; binds to NIL
+ | ( <symbol> ) ; likewise
+ | <clause1>
+ <clause1> ::= ( <symbol>+ <form> ) ; binding
+ | ( <clause1>+ ) ; nesting
+When a clause begins with more than one variable name, they are to be bound to
+successive values of the form. The nesting of clauses indicates sequencing of
+bindings; more deeply nested clauses may reference bindings of shallower clauses.
+All bindings at a given depth are done in parallel. This allows arbitrary
+combinations of parallel and sequential binding. Standard declarations at the
+head of BODY are handled correctly, though nonstandard ones may not be. If two
+variables of the same name are bound at different levels, any declaration
+applies to the inner one."
+ (multiple-value-bind (decls body)
+ (analyze-decls clauses body)
+ (car (expand-new-let clauses body decls))))
+
+;;; Alternative name for the above. I could have this one expand into that
+;;; one, or conversely, but I'd want to duplicate the doc string anyway, and
+;;; that's most of the code.
+(defmacro nlet (clauses &body body)
+ "A generalization of CL:LET that better supports nested bindings and multiple
+values. Syntax: (let (<clause>*) <body>). The <clause> syntax is more general
+than for CL:LET:
+ <clause> ::= <symbol> ; binds to NIL
+ | ( <symbol> ) ; likewise
+ | <clause1>
+ <clause1> ::= ( <symbol>+ <form> ) ; binding
+ | ( <clause1>+ ) ; nesting
+When a clause begins with more than one variable name, they are to be bound to
+successive values of the form. The nesting of clauses indicates sequencing of
+bindings; more deeply nested clauses may reference bindings of shallower clauses.
+All bindings at a given depth are done in parallel. This allows arbitrary
+combinations of parallel and sequential binding. Standard declarations at the
+head of BODY are handled correctly, though nonstandard ones may not be. If two
+variables of the same name are bound at different levels, any declaration
+applies to the inner one."
+ (multiple-value-bind (decls body)
+ (analyze-decls clauses body)
+ (car (expand-new-let clauses body decls))))
+
+(defun expand-new-let (clauses body decls)
+ (labels ((expand-1 (this-level-single this-level-multiple next-level body decls)
+ (cl:cond ((and this-level-multiple
+ (null (cdr this-level-multiple))
+ (null this-level-single))
+ (cl:let ((vars (butlast (car this-level-multiple))))
+ (multiple-value-bind (body decls)
+ (expand-1 nil nil next-level body decls)
+ (values `((multiple-value-bind ,vars
+ ,(car (last (car this-level-multiple)))
+ ,@(bound-decls decls vars)
+ ,@(and (null next-level)
+ (mapcar #'(lambda (d) `(declare ,d))
+ (cdr decls)))
+ . ,body))
+ (prune-decls decls vars)))))
+ (this-level-multiple
+ (let* ((vars (butlast (car this-level-multiple)))
+ (gensyms (mapcar #'(lambda (x)
+ (declare (ignore x))
+ (gensym))
+ vars)))
+ (multiple-value-bind (body decls)
+ (expand-1 (append (mapcar #'list vars gensyms)
+ this-level-single)
+ (cdr this-level-multiple) next-level body decls)
+ (values `((multiple-value-bind ,gensyms
+ ,(car (last (car this-level-multiple)))
+ ,@(bound-decls decls vars)
+ ,@(and (null next-level)
+ (mapcar #'(lambda (d) `(declare ,d))
+ (cdr decls)))
+ . ,body))
+ (prune-decls decls vars)))))
+ (this-level-single
+ (cl:let ((vars (mapcar #'(lambda (x) (if (consp x) (car x) x))
+ this-level-single)))
+ (multiple-value-bind (body decls)
+ (expand-1 nil nil next-level body decls)
+ (values `((cl:let ,this-level-single
+ ,@(bound-decls decls vars)
+ ,@(and (null next-level)
+ (mapcar #'(lambda (d) `(declare ,d))
+ (cdr decls)))
+ . ,body))
+ (prune-decls decls vars)))))
+ (next-level
+ (expand-new-let next-level body decls))
+ (t (values body decls)))))
+ (multiple-value-bind (this-level-single this-level-multiple next-level)
+ (split-level clauses nil nil nil)
+ (expand-1 this-level-single this-level-multiple next-level body decls))))
+
+(defun split-level (clauses this-level-single this-level-multiple next-level)
+ (if (null clauses)
+ (values (reverse this-level-single) (reverse this-level-multiple)
+ next-level)
+ (cl:let ((clause (car clauses)))
+ (cl:cond ((and (listp clause) (listp (car clause)))
+ (split-level (cdr clauses) this-level-single this-level-multiple
+ (append next-level clause)))
+ ((and (listp clause) (cddr clause))
+ (split-level (cdr clauses) this-level-single
+ (cons clause this-level-multiple) next-level))
+ (t
+ (split-level (cdr clauses) (cons clause this-level-single)
+ this-level-multiple next-level))))))
+
+(defun bound-decls (decls vars)
+ (let* ((bd-alist (car decls))
+ (prs (remove-if-not #'(lambda (pr) (member (car pr) vars))
+ bd-alist)))
+ (and prs `((declare . ,(mapcar #'(lambda (pr)
+ (if (listp (cdr pr))
+ `(,@(cdr pr) ,(car pr))
+ `(,(cdr pr) ,(car pr))))
+ prs))))))
+
+(defun prune-decls (decls vars)
+ (cl:let ((bd-alist (car decls)))
+ (cons (remove-if #'(lambda (pr) (member (car pr) vars))
+ bd-alist)
+ (cdr decls))))
+
+(defun analyze-decls (clauses body)
+ "Returns two values. The first value is a cons of: (a) for the bound declarations
+at the head of `body', an alist from variable name to a list of declarations
+affecting that variable; (b) a list of the remaining (free) declarations. The
+second value is `body' with the declarations stripped off."
+ (labels ((process-declares (body bd-alist free vars)
+ (if (or (null body) (not (consp (car body)))
+ (not (eq (caar body) 'declare)))
+ (values bd-alist free body)
+ (multiple-value-bind (bd-alist free)
+ (process-decls (cdar body) bd-alist free vars)
+ (process-declares (cdr body) bd-alist free vars))))
+ (process-decls (decls bd-alist free vars)
+ (if (null decls)
+ (values bd-alist free)
+ (multiple-value-bind (bd-alist free)
+ (process-decl (car decls) bd-alist free vars)
+ (process-decls (cdr decls) bd-alist free vars))))
+ (process-decl (decl bd-alist free vars)
+ (cl:cond
+ ((not (consp decl)) ; defensive programming
+ (values bd-alist (cons decl free)))
+ ((member (car decl) '(ignore ignoreable))
+ ;; These are always bound.
+ (values (append (mapcar #'(lambda (x) (cons x (car decl)))
+ (cdr decl))
+ bd-alist)
+ free))
+ ((type-specifier-name? (car decl))
+ (process-vars (cdr decl) (list 'type (car decl)) bd-alist free vars))
+ ((eq (car decl) 'type)
+ (process-vars (cddr decl) (list 'type (cadr decl)) bd-alist free vars))
+ ((eq (car decl) 'special)
+ (process-vars (cdr decl) (car decl) bd-alist free vars))
+ (t (values bd-alist (cons decl free)))))
+ (process-vars (decl-vars decl-name bd-alist free vars)
+ (if (null decl-vars)
+ (values bd-alist free)
+ (multiple-value-bind (bd-alist free)
+ (process-vars (cdr decl-vars) decl-name bd-alist free vars)
+ (if (member (car decl-vars) vars)
+ (values (cons (cons (car decl-vars) decl-name)
+ bd-alist)
+ free)
+ (values bd-alist
+ (cons (list decl-name (car decl-vars))
+ free)))))))
+ (multiple-value-bind (bd-alist free body)
+ (process-declares body nil nil (new-let-bound-vars clauses))
+ (values (cons bd-alist free) body))))
+
+(defun new-let-bound-vars (clauses)
+ (and clauses
+ (append (cl:let ((clause (car clauses)))
+ (cl:cond ((symbolp clause) (cons clause nil))
+ ((symbolp (car clause)) (butlast clause))
+ (t (new-let-bound-vars clause))))
+ (new-let-bound-vars (cdr clauses)))))
+
+(defun type-specifier-name? (x)
+ (or (member x '(array atom bignum bit bit-vector character compiled-function
+ complex cons double-float extended-char fixnum float function
+ hash-table integer keyword list long-float nil null number
+ package pathname random-state ratio rational real readtable
+ sequence short-float simple-array simple-bit-vector
+ simple-string simple-vector single-float standard-char stream
+ string base-char symbol t vector))
+ (find-class x nil)))
+
+
+(defmacro cond (&rest clauses)
+ "A generalization of CL:COND that makes it convenient to compute a value in
+the predicate expression of a clause and then use that value in the consequent.
+If the predicate expression is a LET form, then the scope of the variables bound
+by the LET is extended to include the consequent expressions. For example:
+
+ (cond ((let ((x (foo)))
+ (bar x))
+ (baz x)))
+
+Here the X in (BAZ X) is the one bound to the result of (FOO)."
+ (cl:let ((block-nm (gensym)))
+ `(block ,block-nm
+ . ,(mapcar #'(lambda (c) (bcond-clause c block-nm)) clauses))))
+
+(defmacro bcond (&rest clauses)
+ "A generalization of CL:COND that makes it convenient to compute a value in
+the predicate expression of a clause and then use that value in the consequent.
+If the predicate expression is a LET form, then the scope of the variables bound
+by the LET is extended to include the consequent expressions. For example:
+
+ (cond ((let ((x (foo)))
+ (bar x))
+ (baz x)))
+
+Here the X in (BAZ X) is the one bound to the result of (FOO)."
+ (cl:let ((block-nm (gensym)))
+ `(block ,block-nm
+ . ,(mapcar #'(lambda (c) (bcond-clause c block-nm)) clauses))))
+
+(defun bcond-clause (clause block-nm)
+ (cl:cond ((not (listp clause))
+ (error "COND clause is not a list: ~S" clause))
+ ((and (listp (car clause))
+ ;; Allow NLET and CL:LET in case the user hasn't chosen
+ ;; to shadow LET.
+ (member (caar clause) '(let nlet cl:let)))
+ (bcond-build-clause (caar clause) (cadar clause)
+ `(progn . ,(cddar clause))
+ (cdr clause) block-nm))
+ (t
+ (bcond-build-clause nil nil (car clause) (cdr clause) block-nm))))
+
+(defun bcond-build-clause (let-sym let-clauses pred consequents block-nm)
+ (cl:let ((body (if consequents
+ `(if ,pred (return-from ,block-nm (progn . ,consequents)))
+ (cl:let ((temp-var (gensym)))
+ `(cl:let ((,temp-var ,pred))
+ (if ,temp-var (return-from ,block-nm ,temp-var)))))))
+ (if let-clauses
+ `(,let-sym ,let-clauses ,body)
+ body)))
+
+
+
1
0