Language GNU Make
(pure make, no math)
Date: | 03/24/06 |
Author: | Krzysztof Nosek |
URL: | n/a |
Comments: | 2 |
Info: | http://www.gnu.org/software/make/ |
Score: | (2.98 in 54 votes) |
# Put the code in some FILE, call: # make -f FILE # or # make # if FILE happens to be just `makefile'. # Number of bottles to drink: BOTTLES := 99 # Overload this variable from the command line in case of make's trouble with memory, e.g.: # make BOTTLES=50 .PHONY: $(BOTTLES) all: 0; # No more bottles of beer on the wall, no more bottles of beer. # Go to the store and buy some more, $(BOTTLES) bottles of beer on the wall. define chain $1: $2; # $$(subst 1 bottles,1 bottle,$$< bottles of beer on the wall, $$< bottles of beer.) # Take one down and pass it around, $$(patsubst 0,no more,$$@) bottles of beer on the wall. # endef tail = $(wordlist 2,$(words $1),$1) make-a-chain = $(if $1,$(eval $(call chain,$(words $(call tail,$1)),$(words $1))) \ $(call make-a-chain,$(call tail,$1))) ten := x x x x x x x x x x $(call make-a-chain,$(wordlist 1,$(BOTTLES),$(foreach \ (c) nosek 2006. Credits to John Graham-Cumming's GMSL!,$(ten),$(ten))))
Download Source | Write Comment
Download Source | Write Comment
Add Comment
Please provide a value for the fields Name,
Comment and Security Code.
This is a gravatar-friendly website.
E-mail addresses will never be shown.
Enter your e-mail address to use your gravatar.
Please don't post large portions of code here! Use the form to submit new examples or updates instead!
Comments
Krzysztof Nosek said on 03/24/06 23:13:11
So, some bug with evaluating to '1 bottle' happened to me too... Solving it, I needed to add an extra function. Pity :-( but now works fine. Here're differences:
@@ -17,6 +17,8 @@
define chain
-$1: $2; # $$(subst 1 bottles,1 bottle,$$< bottles of beer on the wall, $$< bottles of beer.)
- # Take one down and pass it around, $$(patsubst 0,no more,$$@) bottles of beer on the wall.
+$1: $2; # $$(call beer,$2) on the wall, $$(call beer,$2).
+ # Take one down and pass it around, $$(call beer,$$(patsubst 0,no more,$1)) on the wall.
#
endef
+
+beer = $(subst ~,,$(subst ~1 bottles,1 bottle,~$1 bottles of beer))
Phil Ashby said on 04/12/07 00:20:01
Nice work Krzysztof, I was a lot less familiar with GNU make at the time